0

I am trying to create a grouped bar chart after using the groupby function in Pandas. But I am not so sure how to generate the bar chart using the grouped columns Counter and tag as x-axis while count as y axis.

The expected outcome is show the number of count of each Counter with grouped tag.

result2 = df.groupby(['Counter','tag'])['Counter'].agg(['count'])
result2.sort_values(by='count', ascending=False).reset_index()
result2
Counter tag             count
1       F&B             48
2       Accomodation    8
        F&B             7
3       Accomodation    4
        F&B             6
        Tickets         1

I tried to generate with the code below, but received an error message.

result2.plot(x=['Counter','tag'], y='count', kind='bar')
ValueError: x must be a label or position

Expected outcome

Counter as x-axis (like the date 2020Q1), with tag (the names in the chart) where y-axis displays the count (Net revenue in the chart).

enter image description here

NordicFox
  • 123
  • 2
  • 10

0 Answers0