pandas || groupby()+shift() = analog SQL LAG
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n#1 Data preparation\n#2
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n#1 Data preparation\n#2 Attach a column `next_event_date` using `groupby` + `shift` (analog SQL LAG)\n#3 Leave only the first lines for each user\n#4 Create a "boolean pd.series" by checking "players that logged in again on the day after the day they first logged in" + mean().round(2)\n#5 Create result DataFrame\n\n# Code\n```\nimport pandas as pd\n\ndef gameplay_analysis(activity: pd.DataFrame) -> pd.DataFrame:\n    # 1\n    df = activity[[\'player_id\',\'event_date\']].drop_duplicates().sort_values(by = \'event_date\')\n    # 2\n    df[\'next_event_date\'] = df.groupby(\'player_id\')[\'event_date\'].shift(-1)\n    # 3\n    df = df.groupby(\'player_id\').first()\n    # 4\n    t = (df[\'next_event_date\'] == (df[\'event_date\'] + pd.DateOffset(days = 1))).mean().round(2)\n    # 5\n    return pd.DataFrame({\'fraction\':[t]})\n```
['Pandas']