0

I have been trying to do an aggregated bar plot by using groupby multiple columns of my dataframe. My dataframe looks like the below one, with quite a few extra columns (not included here)

Revenue per day | Month | Customer
   150          |  Jan  |    A
   120          |  Jan  |    B
   330          |  Jan  |    C
   .
   .
   .
   250          |  Dec  |    A

I am trying to draw a barplot comprising of the cumulative sum of the revenue, grouped by month and the customer. If it would have been categorical data, I could have used Pandas.crosstab() function for plotting but since it is numerical data, I can only group by one single column and not both. My approach is as follows :

df['new_grouped_col'] = df.groupby(['Month', 'Customer'])['Revenue per day'].cumsum()
df.plot.bar()

But it returns nothing

Soumya C
  • 117
  • 10
  • Absolutlely nothing happens? No error? Did you run `matplotlib.pyplot.show()`? Also, why are you not specifying `x` and `y` arguments given your many columns? See [docs](https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.plot.html) – Parfait Mar 12 '22 at 17:39
  • I had added plt.show() but the command runs for more than one hour after which I am killing it. Other line plots are displayed within 1-2 mins – Soumya C Mar 13 '22 at 00:10
  • 1
    I suggest providing a [minimal, complete, and reproducible example](https://stackoverflow.com/help/minimal-reproducible-example). See also [How to make good reproducible pandas examples](https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples). It should not take forever to group some data. – Mr. T Mar 13 '22 at 09:57

0 Answers0