
Pins by category
mediumPins by category
Pinterest Pandas Interview Question
Pinterest's creator team wants a quick view of what each creator pins about, with one row per creator.
Using the pins DataFrame, return one row per user_id with the number of pins they created in each category as three columns: DIY, Food and Travel. Show 0 when a creator has no pins in a category. Assign the answer to result.
Asked of
- Data Analyst
- Product Analyst
- Business Analyst
- Analytics Engineer
- Data Scientist
pinsDataFrame20 rows
| Column Name | Type |
|---|---|
| pin_id | int64 |
| user_id | int64 |
| category | str |
| created_at | str |
| saves | int64 |
pinsExample Input
| pin_id | user_id | category | created_at | saves |
|---|---|---|---|---|
| 1 | 701 | Food | 2024-07-01 | 14 |
| 2 | 701 | Food | 2024-07-01 | 3 |
| 3 | 702 | Travel | 2024-07-02 | 27 |
| 4 | 701 | DIY | 2024-07-02 | 8 |
| 5 | 703 | DIY | 2024-07-03 | 5 |
| 6 | 702 | Travel | 2024-07-03 | 11 |
| 7 | 704 | Food | 2024-07-04 | 2 |
| 8 | 703 | Travel | 2024-07-04 | 19 |
Example Output
| user_id | DIY | Food | Travel |
|---|---|---|---|
| 701 | 1 | 2 | 0 |
| 702 | 0 | 0 | 2 |
| 703 | 1 | 0 | 1 |
| 704 | 0 | 1 | 0 |
Explanation
User 701 created one DIY pin and two Food pins in the example, and no Travel pins, so that row shows 1, 2 and 0. User 702 only pinned Travel, so their DIY and Food columns are 0.
The example above is a small slice of the data. Your code runs against the full DataFrames.
Company
Pinterest
Difficulty
medium
Topic
reshaping
Language
Pandas
Your code
Loading Python in the background. You can start writing.