
Shops per tag
mediumShops per tag
Etsy Pandas Interview Question
Etsy's search team wants to know which shop tags are most common. Shops list their tags in one text column, separated by a vertical bar, and some shops put spaces around the bar.
Using the shops DataFrame, find each tag and the number of shops that use it as shop_count. Sort the rows by shop_count, highest first, and then by tag from A to Z. Assign the answer to result.
Asked of
- Data Analyst
- Product Analyst
- Business Analyst
- Analytics Engineer
- Data Scientist
shopsDataFrame10 rows
| Column Name | Type |
|---|---|
| shop_id | int64 |
| shop_name | str |
| tags | str |
| opened_year | int64 |
shopsExample Input
| shop_id | shop_name | tags | opened_year |
|---|---|---|---|
| 4101 | Oak and Thread | handmade|home decor | 2019 |
| 4102 | Rust Belt Finds | vintage | home decor | 2016 |
| 4103 | Little Lantern Co | handmade|jewelry|gifts | 2021 |
| 4104 | Second Spin Records | vintage | 2014 |
| 4105 | Clay Moon Studio | handmade | ceramics | home decor | 2020 |
| 4106 | Fern and Fable | jewelry|gifts | 2022 |
| 4107 | Pressed Petals | handmade|gifts | 2018 |
| 4108 | Retro Rewind | vintage|clothing | 2017 |
Example Output
| tag | shop_count |
|---|---|
| handmade | 4 |
| gifts | 3 |
| home decor | 3 |
| vintage | 3 |
| jewelry | 2 |
| ceramics | 1 |
| clothing | 1 |
Explanation
Clay Moon Studio writes its tags with spaces around each bar, and they still count under the same names as everyone else's. Handmade appears on four shops in the example, so it comes first. Gifts, home decor and vintage each appear on three shops, so they are listed alphabetically.
The example above is a small slice of the data. Your code runs against the full DataFrames.
Company
Etsy
Difficulty
medium
Topic
strings
Language
Pandas
Your code
Loading Python in the background. You can start writing.