我刚刚开始学习 pandas,当时我想制作 2013 年车站平均值的条形图,以创建一个fig, ax = plt.subplots()
对象并将绘图添加到创建的 ax' 我在运行这部分代码时收到此错误 'Line2D' 对象没有属性 'kind'
fig,ax = plt.subplots(1)
x= data.columns
y=data['2013'].mean()
ax.plot(x,y,kind='bar')
```````````````````````
[this is my DATASET]
L06_347 LS06_347 LS06_348
Time
2009-01-01 00:00:00 0.137417 0.097500 0.016833
2009-01-01 03:00:00 0.131250 0.088833 0.016417
2009-01-01 06:00:00 0.113500 0.091250 0.016750
2009-01-01 09:00:00 0.135750 0.091500 0.016250
... ... ... ...
2013-01-01 15:00:00 1.420000 1.420000 0.096333
2013-01-01 18:00:00 1.178583 1.178583 0.083083
2013-01-01 21:00:00 0.898250 0.898250 0.077167
2013-01-02 00:00:00 0.860000 0.860000 0.075000
11697 rows × 3 columns
另一方面,我尝试使用此代码选择所有不同年份的四月、五月和六月的所有数据
data[(data.index.month == 4) & (data.index.month == 5) & (data.index.month == 6)]
我也尝试过这种方式
data.loc[(data.index.month == 4) & (data.index.month == 5) & (data.index.month == 6)]
它没有向我显示任何内容,只是显示空列。
对于你的第一个问题,你必须使用data.plot(x, y, kind='bar')
, not ax.plot()
.
fig,ax = plt.subplots(1)
ax = data['2013'].mean().plot(kind='bar')
ax.set_xlabel('x label name') # replace with the labels you want
ax.set_ylabel('Mean')
plt.xticks(rotation=30)
plt.show()
对于你的第二个问题 - 使用data[data.index.month.isin([4,5,6])]
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)