I have a dataframe like this:
df = {'product_type_name':
['Calendar', 'Lanyard', 'Name Card', 'Paper Lunch Box', 'Plastic Cup', 'Poster', 'Sticker', 'T-Shirt', 'Tote Bag'],
'order_count':
[4, 44, 14, 8, 6, 39, 28, 28, 17]}
df = pd.DataFrame(df)
print(df)
Output:
I want to group each product_type_name into four categories that goes like this:
- Packaging (Paper Lunch Box, Plastic Cup)
- Marketing Materials (Poster, Sticker)
- Office Supplies (Name Card, Calendar, Lanyard)
- Merchandise (Tote Bag, T-Shirt)
After that I want to summarize total order for each categories based on this rules:
- High (order >= 10)
- Medium (order 6 - 9)
- Low (order <=5)
The expected output is going to be like this:
| category | high | medium | low |
|---|---|---|---|
| Packaging | Null | Paper Lunch Box, Plastic Cup | Null |
| Marketing Materials | Poster, Sticker | Null | Null |
| Office Supplies | Lanyard, Name Card | Null | Calendar |
| Merchandise | Tote Bag, T-Shirt | Null | Null |
My solution is first to make a column which contains 3 class: high, medium, low based on orders rules above.Then, make the summarize table. The problem is I don't know how to do the summarize table. Any idea how to solve this problem for me?
EDIT
I made the python live code: https://paiza.io/projects/uhBOkwo5OZkOx4eg6bdSCw

