Python大熊猫绘制季度值

Sanito Machiavelli

接收错误:freq尝试从索引值为2006Q1之类的DataFrame进行绘图时,轴必须已设置为转换为Periods

 df1 = SalesReport[['Time','Product1','Product2','Product3']]
 df1['Time'] = pd.to_datetime(df1['Time'], format='%d/%m/%y')
 df1 = df1.set_index('Time')
 df1.index = df1.index.to_period("Q")

结果得到了所需格式的数据并对此感到满意:

        Product1   Product2   Product3
Time                                   
2005Q4  5023203.0  6718023.0  3964175.0
2006Q1  5048207.0  6735528.0  3987653.0
2006Q2  5061266.0  6742690.0  4007992.0

但是现在当我尝试绘制时:

plt.plot(df1)
plt.show()

收到错误:轴必须已freq设置为转换为“句点”

绘制这种类型的dataFrame的正确方法是什么?

要么

我不知道为什么无法使用它的原因,plt.plot()但是您可以尝试使用pandasplot函数进行绘制,该函数还使用了matplotlib ...我正在使用Python 3和pandas 0.20

df.plot()

在此处输入图片说明

参考

https://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.plot.html

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章