Skip to content

Commit d33a1c4

Browse files
committed
Create 550. Game Play Analysis IV.py
1 parent 904d8b4 commit d33a1c4

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import pandas as pd
2+
3+
def game_play_analysis(activity: pd.DataFrame) -> pd.DataFrame:
4+
# Get first login date for each player
5+
first_login = activity.groupby("player_id")["event_date"].min().reset_index()
6+
first_login.columns = ["player_id", "first_login"]
7+
8+
# Merge first login date with original table
9+
merged = activity.merge(first_login, on="player_id")
10+
11+
# Filter players who logged in the next day
12+
next_day_logins = merged[
13+
(merged["event_date"] - merged["first_login"]).dt.days == 1
14+
]["player_id"].nunique()
15+
16+
# Total unique players
17+
total_players = activity["player_id"].nunique()
18+
19+
# Calculate fraction
20+
fraction = round(next_day_logins / total_players, 2)
21+
22+
return pd.DataFrame({"fraction": [fraction]})

0 commit comments

Comments
 (0)