First Sign-Ins by Day
Problem
A streaming service logs each action a viewer takes, including their sign-ins, in a DataFrame `viewer_event` (`viewer_event.csv`).
```text
+-------------+--------+
| Column | Type |
+-------------+--------+
| viewer_id | int |
| action | object |
| acted_on | object |
+-------------+--------+
```
There may be many rows per viewer. The `action` column holds values such as `'signin'`, `'browse'`, and `'signout'`.
Write a function that reports, for each date within the last 90 days, how many viewers signed in for the very first time on that date. A viewer's first sign-in is the earliest date on which they have a `'signin'` action. Assume today is 2023-06-30, so only first sign-ins on or after 2023-04-01 should appear. Return columns `first_signin_date` and `new_viewers` in any order. Only include dates with at least one first-time sign-in.
Input data
Example rows — the live problem includes the full dataset.
| viewer_id | action | acted_on |
|---|---|---|
| 1 | signin | 2023-05-01 |
| 1 | browse | 2023-05-01 |
| 1 | signout | 2023-05-01 |
| 2 | signin | 2023-06-21 |
| 2 | signout | 2023-06-21 |
Expected output
Your answer should return 2 rows with the columns first_signin_date, new_viewers.
Starter code (Pandas (Python))
import pandas as pd
def first_signins(viewer_event: pd.DataFrame) -> pd.DataFrame:
# Your code here
return viewer_eventSolve this Pandas question free
Write Pandas (Python) and run it instantly in your browser — even on your phone. No signup needed to try.
Solution & explanation
Create a free account to unlock the optimal solution, a step-by-step explanation, and the hidden test cases that grade your answer.
Sign up free to unlock