AttributeError: 'function' 对象在 Pandas 中没有属性 'bar'

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/36856428/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 01:07:18  来源:igfitidea点击:

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

pythonpandas

提问by Baktaawar

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

我有一个Pandas数据框,它是Pandas数据框类型,如下所示

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?

不是箱线图或 hist 等其他功能也不起作用。知道为什么吗?

回答by CoderBC

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

如果您有要绘制的特定列,可以尝试: df.plot(x='x', y='y', kind='bar')

回答by jezrael

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:

我认为你需要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

图形