pandas || filter and groupby || T/S: 90% / 93%
Here\'s the plan:\n\n1. We attach a column first_day to activity in which each entry is the first day for that player.\n\n1. We attach a column is_day to activi
Here\'s the plan:\n\n1. We attach a column `first_day` to `activity` in which each entry is the first day for that player.\n\n1. We attach a column `is_day` to `activity` in which each entry is the boolean `event_date == first_day + 1 day`.\n1. We filter `activity` to those rows for which `is_day` is true.\n1. We return the ratio of (a) the unique players after the filtering and (b) the unique players in before the filtering.\n```\nimport pandas as pd\n\ndef gameplay_analysis(activity: pd.DataFrame) -> pd.DataFrame:\n    \n    activity["first_day"] = activity.groupby(                       # <-- 1.  \n                   ["player_id"])[["event_date"]].transform("min")\n\n    activity["is_day"] = (activity.event_date - activity.first_day)  # <-- 2. \n                        .dt.total_seconds() == 86400\n\n    df = activity[activity[\'is_day\']]                               # <-- 3. \n \n    return pd.DataFrame({"fraction":[round(                         # <-- 4. \n                    df.player_id.nunique() / activity.player_id.nunique(),2)]})\n```\n[https://leetcode.com/problems/game-play-analysis-iv/submissions/1077819133/](http://)\n\n\n\nI could be wrong, but I think that time complexity is *O*(*N*) and space complexity is *O*(*N*), in which *N* ~ `len(activity)`.
['Pandas']