0

My DataFrame is below

  Month  Sales2015  Sales2016
0    Q3       0.00   13208.52
1    Q4   10500.78   23114.91
2    Q2       0.00    6627.00
3    Q1   19881.00   13254.00
4    Q3    3684.48       0.00

My code is below

sa[['Month','Sales2015','Sales2016']].plot(kind='bar')

sa[['Month','Sales2015','Sales2016']].plot(kind='bar')

But this graph is not correct. I need to

  • Compare quarter-wise sales in 2015 and 2016 in a bar plot

  • Create a pie chart with Month and Sales2016

ALollz
  • 57,915
  • 7
  • 66
  • 89

1 Answers1

1

I will use GroupBy.sum.

df.groupby('Month').sum().plot(kind='bar')
#print(df.groupby('Month').first())

#       Sales2015  Sales2016
#Month                      
#Q1      19881.00   13254.00
#Q2          0.00    6627.00
#Q3          0.00   13208.52
#Q4      10500.78   23114.91

enter image description here


df.groupby('Month').sum().plot.pie(subplots=(1,len(df.columns[1:])),figsize=(10,10))

#array([<matplotlib.axes._subplots.AxesSubplot object at 0x7f1303f64a20>,
#       <matplotlib.axes._subplots.AxesSubplot object at 0x7f1303f29048>],
#      dtype=object)

enter image description here

ansev
  • 30,322
  • 5
  • 17
  • 31
  • can you explain this `for i,ax in enumerate(axs): agg_df.plot.pie(y=list_sales[i],ax=ax) ` –  Jan 15 '20 at 16:42
  • 1
    with plt.subplots two axes are generated where to draw the graph and with the loop reference is made to it. But you can use the second solution that I just published – ansev Jan 15 '20 at 16:44
  • How to get the values also on the char like `https://stackoverflow.com/questions/41088236/how-to-have-actual-values-in-matplotlib-pie-chart-displayed-python` –  Jan 16 '20 at 02:49