
Watch time by genre
easyWatch time by genre
Netflix Pandas Interview Question
Netflix's content team wants to see which genres members spend the most time watching.
Using the viewing_activity and titles DataFrames, return each genre with the total minutes watched as minutes_watched. Sort the rows by minutes_watched, highest first. Assign the answer to result.
Asked of
- Data Analyst
- Product Analyst
- Business Analyst
- Analytics Engineer
- Data Scientist
viewing_activityDataFrame16 rows
| Column Name | Type |
|---|---|
| view_id | int64 |
| profile_id | int64 |
| title_id | int64 |
| country | str |
| watch_date | str |
| minutes_watched | int64 |
titlesDataFrame6 rows
| Column Name | Type |
|---|---|
| title_id | int64 |
| title_name | str |
| content_type | str |
| genre | str |
| runtime_minutes | int64 |
viewing_activityExample Input
| view_id | profile_id | title_id | country | watch_date | minutes_watched |
|---|---|---|---|---|---|
| 1 | 1001 | 1 | United States | 2024-08-01 | 118 |
| 2 | 1002 | 4 | United States | 2024-08-01 | 58 |
| 3 | 1003 | 4 | United States | 2024-08-02 | 30 |
| 4 | 1004 | 3 | United States | 2024-08-02 | 45 |
| 5 | 1005 | 1 | Brazil | 2024-08-02 | 60 |
| 6 | 1006 | 6 | Brazil | 2024-08-03 | 52 |
| 7 | 1007 | 6 | Brazil | 2024-08-03 | 52 |
| 8 | 1008 | 2 | Brazil | 2024-08-03 | 92 |
titlesExample Input
| title_id | title_name | content_type | genre | runtime_minutes |
|---|---|---|---|---|
| 1 | Midnight Heist | Movie | Thriller | 118 |
| 2 | Ocean Deep | Movie | Documentary | 92 |
| 3 | Kitchen Wars | Series | Reality | 45 |
| 4 | The Last Colony | Series | Sci-Fi | 58 |
| 5 | Laugh Track | Movie | Comedy | 101 |
| 6 | Crown of Ash | Series | Drama | 52 |
Example Output
| genre | minutes_watched |
|---|---|
| Thriller | 178 |
| Drama | 104 |
| Documentary | 92 |
| Sci-Fi | 88 |
| Reality | 45 |
Explanation
In the example, Thriller comes first with 178 minutes: 118 and 60 minutes of Midnight Heist. The Sci-Fi series The Last Colony was watched for 58 and 30 minutes, 88 in total.
The example above is a small slice of the data. Your code runs against the full DataFrames.
Company
Netflix
Difficulty
easy
Topic
joins
Language
Pandas
Your code
Loading Python in the background. You can start writing.