如何在同一图表上正确绘制个别年份的月度数据

时间:2020-01-26 05:14:38

标签: python pandas matplotlib

我有一些特定年份的商店的销售数据,我想绘制其每月销售数据。 在这里,我有DateTime对象,因此通过此对象,我可以这样绘制

wlmrt['Date'].dt.month.value_counts().sort_index().plot()
# Here it's output actually it's output is graph but to show its error I am showing it's value
1     450
2     495
3     540
4     630
5     585
6     540
7     585
8     540
9     585
10    585
11    405
12    495

我认为它可以将不同年份的同一个月进行分组并进行绘制,但是我希望可以绘制出每年每个月的销售数据

1 个答案:

答案 0 :(得分:1)

wlmrt['Date'].resample('M').count().plot()

应该做到这一点。 pandas.DataFrame.resample 是一种“ 频率转换和重采样的便捷方法”,返回的count()对象的Resampler方法为每个重采样周期生成一个计数,作为{{ 1}},然后可以使用典型的DataFrame方法进行绘制。