[英]How can I fix data frame has no attribute plot
dd=df.select(df.Color,df.ListPrice.cast("float"))
colordf = dd[['Color','ListPrice']]
colordfgroup = colordf.groupby('Color').mean('ListPrice')
colordfgroup.show()
my_plot = colordfgroup.plot(kind='bar')
It shows me that DataFrame has no attribute plot.它告诉我 DataFrame 没有属性 plot。
All data frame type is a string.所有数据帧类型都是字符串。
I commented the line colordfgroup.show() and corrected mean calculation我评论了 colordfgroup.show() 行并修正了平均计算
dd=df.select(df.Color,df.ListPrice.cast("float"))
colordf = dd[['Color','ListPrice']]
colordfgroup = colordf.groupby('Color')['ListPrice'].mean()
#colordfgroup.show()
my_plot = colordfgroup.plot(kind='bar')
Here is a minimal example这是一个最小的例子
import pandas as pd
import matplotlib.pyplot as plt
colors = ['A', 'B', 'C', 'D', 'A', 'B', 'C', 'D', ]
lp = [10.0, 20.0, 30.0, 40.0, 12.0, 22.0, 32.0, 42.0 ]
colordf = pd.DataFrame(data = {'Color': colors, 'ListPrice':lp}, index = [x for x in range(len(colors))])
colordfgroup = colordf.groupby('Color')['ListPrice'].mean()
my_plot = colordfgroup.plot(kind='bar')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.