Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AttributeError: 'function' object has no attribute 'bar' in pandas

Tags:

python

pandas

I have a pandas data frame which is a pandas data frame type as shown below

type(df)

Out[176]:

pandas.core.frame.DataFrame

But when I try to use any plotting functions on this data frame like bar graph it gives an error as follows;

df.plot.bar()

AttributeError: 'function' object has no attribute 'bar'

Not other function like box plot or hist is also not working. Any idea why?

like image 765
Baktaawar Avatar asked Oct 22 '25 12:10

Baktaawar


2 Answers

If you have specific columns in mind that you want to plot, you can try: df.plot(x='x', y='y', kind='bar')

like image 192
CoderBC Avatar answered Oct 25 '25 00:10

CoderBC


Interesting, for me it works very well:

df = pd.DataFrame({'ab': {0: 31196, 1: 18804}})
print df

      ab
0  31196
1  18804

#New in version 0.17.0.
df.plot.bar()

Another option:

df.plot(kind='bar')

graph

EDIT (by discussion in chat):

I think you need boxplot:

#filter columns
df = df.drop(['city','last_trip_date','phone','signup_date','user_red'], axis=1)
print df
   Retained  avg_dist  avg_increase  avg_price  avg_value   pct  \
0         1      3.67           1.1        5.0        4.7  15.4   
1         0      8.26           1.0        5.0        5.0   0.0   
2         0      0.77           1.0        5.0        4.3   0.0   

   trips_in_first_30_days  weekday_pct  
0                     4.0         46.2  
1                     0.0         50.0  
2                     3.0        100.0  

df.boxplot(by='Retained', layout=(7,1), figsize=(5,15))

graph

like image 42
jezrael Avatar answered Oct 25 '25 00:10

jezrael