i have a table in my pandas df.
Total_orders frequency
0.0 18679137
1.0 360235
2.0 68214
3.0 20512
4.0 7211
... ...
50.0 12
i want to plot a bar graph total orders vs frequency,with the values of frequency displayed on the top of each bars.
i am running these three codes. Code1:
plt.figure(figsize=(12,6))
df2 = df.groupby('Total_orders')['frequency'].plot(kind='bar')
plt.xlabel('Total_orders')
plt.ylabel('frequency')
for rect in df2.patches:
height = rect.get_height()
df2.text(rect.get_x() + rect.get_width()/2., 1.05*height+100,
'%d' % int(height),ha='center', va='bottom', rotation=90)
Code2:(for loop)
for ii,rect in enumerate(df2.patches):
height = rect.get_height()
df2.text(rect.get_x() + rect.get_width()/2., 1.14*height+100,'%d' % int(height),ha='center', va='bottom', rotation=90)
Code3
for p in df2.patches:
df2.annotate(str(p.get_height()), (p.get_x() * 1.005, p.get_height() *1.05),rotation=90)
but when i am running the code it's showing me error, that
AttributeError: 'Series' object has no attribute 'patches'
Any idea why this is happening, and how to remove it? Thanks in advance.