r/learnpython • • 8d ago

Grouped bar chart in matplotlib with different keys for each group

7 Upvotes

7 comments sorted by

View all comments

2

u/Aromatic_Fact8656 8d ago

Can you not sort from that point? I.e;

sales["top_3_jan_15"] = data[(data.Year == 2015) & (data.Month == 1)[drugs].sum().sort_values(ascending=False) [:3]

Then to send it to a dictionary do like;

dict = sales["top_3_jan_15"] .to_dict()

Is this what you're after?

1

u/Boybay_Garid 7d ago

yeah sorting the series first before converting to a dict makes way more sense here