【发布时间】:2016-10-12 15:49:48
【问题描述】:
我有一个如下所示的数据集:
prod_code month items cost
0 040201060AAAIAI 2016-05-01 5 572.20
1 040201060AAAKAK 2016-05-01 164 14805.19
2 040201060AAALAL 2016-05-01 13465 14486.07
执行df.dtypes 表明month 列是datetime64[ns] 类型。
我现在正在尝试绘制特定产品的每月成本:
df[df.bnf_code=='040201060AAAIAI'][['month', 'cost']].plot()
plt.show()
这可行,但 x 轴不是我所期望的时间戳:
如何使用月份和年份标签很好地格式化 x 轴标签?
更新:我也试过这个,得到一个条形图,它在 x 轴上输出时间戳,但格式很长,很笨拙:
df[df.bnf_code=='040201060AAAIAI'].plot.bar(x='month', y='cost', title='Spending on 040201060AAAIAI')
【问题讨论】:
标签: python pandas matplotlib