File tree Expand file tree Collapse file tree 3 files changed +48
-0
lines changed
solution/0500-0599/0550.Game Play Analysis IV Expand file tree Collapse file tree 3 files changed +48
-0
lines changed Original file line number Diff line number Diff line change @@ -107,4 +107,22 @@ FROM T
107107WHERE 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 -->
Original file line number Diff line number Diff line change @@ -102,4 +102,22 @@ FROM T
102102WHERE 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 number Diff line number Diff line change 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+ )
You can’t perform that action at this time.
0 commit comments