Skip to content

Commit 49bf92b

Browse files
committed
Solution for 550.
1 parent 1552bce commit 49bf92b

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,4 +107,21 @@ 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.loc[
119+
activity["first"] + pd.DateOffset(1) == activity["event_date"]
120+
]
121+
return pd.DataFrame(
122+
{"fraction": [round(len(activity_2nd_day) / activity.player_id.nunique(), 2)]}
123+
)
124+
125+
```
126+
110127
<!-- tabs:end -->

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

Lines changed: 18 additions & 0 deletions
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.loc[
114+
activity["first"] + pd.DateOffset(1) == activity["event_date"]
115+
]
116+
return pd.DataFrame(
117+
{"fraction": [round(len(activity_2nd_day) / activity.player_id.nunique(), 2)]}
118+
)
119+
120+
```
121+
122+
105123
<!-- tabs:end -->
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
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.loc[
7+
activity["first"] + pd.DateOffset(1) == activity["event_date"]
8+
]
9+
return pd.DataFrame(
10+
{"fraction": [round(len(activity_2nd_day) / activity.player_id.nunique(), 2)]}
11+
)

0 commit comments

Comments
 (0)