Skip to content

Commit 8be44f3

Browse files
authored
feat: add pandas solution to lc problem: No.0550 (doocs#1891)
* Solution for 511. * Solution for 550. * Update README.md * Update README_EN.md * Update Solution.py * Update Solution.py * Update README_EN.md * Update README.md
1 parent a043718 commit 8be44f3

File tree

3 files changed

+48
-0
lines changed

3 files changed

+48
-0
lines changed

solution/0500-0599/0550.Game Play Analysis IV/README.md

+18
Original file line numberDiff line numberDiff line change
@@ -107,4 +107,22 @@ FROM T
107107
WHERE rk = 1;
108108
```
109109

110+
### **Pandas**
111+
112+
```python
113+
import pandas as pd
114+
115+
116+
def gameplay_analysis(activity: pd.DataFrame) -> pd.DataFrame:
117+
activity["first"] = activity.groupby("player_id").event_date.transform(min)
118+
activity_2nd_day = activity[
119+
activity["first"] + pd.DateOffset(1) == activity["event_date"]
120+
]
121+
122+
return pd.DataFrame(
123+
{"fraction": [round(len(activity_2nd_day) / activity.player_id.nunique(), 2)]}
124+
)
125+
126+
```
127+
110128
<!-- tabs:end -->

solution/0500-0599/0550.Game Play Analysis IV/README_EN.md

+18
Original file line numberDiff line numberDiff line change
@@ -102,4 +102,22 @@ FROM T
102102
WHERE rk = 1;
103103
```
104104

105+
### **Pandas**
106+
107+
```python
108+
import pandas as pd
109+
110+
111+
def gameplay_analysis(activity: pd.DataFrame) -> pd.DataFrame:
112+
activity["first"] = activity.groupby("player_id").event_date.transform(min)
113+
activity_2nd_day = activity[
114+
activity["first"] + pd.DateOffset(1) == activity["event_date"]
115+
]
116+
117+
return pd.DataFrame(
118+
{"fraction": [round(len(activity_2nd_day) / activity.player_id.nunique(), 2)]}
119+
)
120+
121+
```
122+
105123
<!-- tabs:end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import pandas as pd
2+
3+
4+
def gameplay_analysis(activity: pd.DataFrame) -> pd.DataFrame:
5+
activity["first"] = activity.groupby("player_id").event_date.transform(min)
6+
activity_2nd_day = activity[
7+
activity["first"] + pd.DateOffset(1) == activity["event_date"]
8+
]
9+
10+
return pd.DataFrame(
11+
{"fraction": [round(len(activity_2nd_day) / activity.player_id.nunique(), 2)]}
12+
)

0 commit comments

Comments
 (0)