Pins by category

reshaping

Pins 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 NameType
pin_idint64
user_idint64
categorystr
created_atstr
savesint64

pinsExample Input

pin_iduser_idcategorycreated_atsaves
1701Food2024-07-0114
2701Food2024-07-013
3702Travel2024-07-0227
4701DIY2024-07-028
5703DIY2024-07-035
6702Travel2024-07-0311
7704Food2024-07-042
8703Travel2024-07-0419

Example Output

user_idDIYFoodTravel
701120
702002
703101
704010

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.