Shops per tag

strings

Shops 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 NameType
shop_idint64
shop_namestr
tagsstr
opened_yearint64

shopsExample Input

shop_idshop_nametagsopened_year
4101Oak and Threadhandmade|home decor2019
4102Rust Belt Findsvintage | home decor2016
4103Little Lantern Cohandmade|jewelry|gifts2021
4104Second Spin Recordsvintage2014
4105Clay Moon Studiohandmade | ceramics | home decor2020
4106Fern and Fablejewelry|gifts2022
4107Pressed Petalshandmade|gifts2018
4108Retro Rewindvintage|clothing2017

Example Output

tagshop_count
handmade4
gifts3
home decor3
vintage3
jewelry2
ceramics1
clothing1

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.