我正在绘制这样的事情发生的频率:
graph=y.date.groupby(y.date.dt.hour).count().plot(kind='bar')
plt.show()
问题是,时间显示为浮点值:即 8.0、9.0 等,但我希望它以 24 小时时间显示,并且具有一定的时间范围(例如从 0600 到午夜)。我尝试遵循这里的其他一些示例,但无法让它们工作。有什么建议吗?
最佳答案
我不确定为什么月份显示为 float ,但这是显示军事时间的方法:
df['military_time'] = (df.time.dt.hour*100).map("{:04}".format)
time military_time
0 2015-04-19 06:00:00 0600
1 2015-04-19 19:30:00 1900
2 2015-04-19 21:00:00 2100
3 2015-04-19 21:00:00 2100
4 2015-04-19 00:00:00 0000
关于python - 使用 matplotlib 绘图 : hours shown as float,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29736071/