简体   繁体   English

如何修复数据框没有属性 plot

[英]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.

相关问题 如何在python中修复“openCV没有属性VideoCapture” - How can I fix 'openCV has no attribute VideoCapture' in python 如何修复 AttributeError:模块“tensorflow”没有属性“ConfigProto” - How can I fix AttributeError: module 'tensorflow' has no attribute 'ConfigProto' 我该如何修复,AttributeError: 'NoneType' 对象没有属性 'send' - How can I fix, AttributeError: 'NoneType' object has no attribute 'send' 我该如何解决这个问题:AttributeError: 'NoneType' object has no attribute 'strip - How can i fix this :AttributeError: 'NoneType' object has no attribute 'strip 我该如何解决这个问题,AttributeError: module "numbers" has no attribute 'Integral' - How can I fix this, AttributeError: module "numbers" has no attribute 'Integral' AttributeError: 'int' 对象没有属性 'get' 我该如何修复它 - AttributeError: 'int' object has no attribute 'get' how can i fix it AttributeError: 'function' object 没有属性 'read' — 我该如何修复? - AttributeError: 'function' object has no attribute 'read' — HOW CAN I FIX? AttributeError: 'function' object 没有属性 'split'。 我该如何解决? - AttributeError: 'function' object has no attribute 'split'. How I can fix it? 如何使用 plotly 为 dask 数据框绘制交互式图 - how can I plot Interactive plot for a dask data frame using plotly 我该如何修正直方图 - how can I fix my histogram plot
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM