我的数据集如下所示:
Month DeviceType AvgRevenue
0 201608 desktop 3.029642
1 201608 mobile 0.197588
2 201608 tablet 1.575810
3 201609 desktop 2.352156
4 201609 mobile 0.182009
我试着画一个图来可视化它,但是,x轴与原始数据不同,因为我的x轴应该是年和月,图上显示的x轴是不合理的…我如何纠正这个问题?谢谢
fig, ax = plt.subplots()
for name, group in device.groupby('DeviceType'):
group.plot('Month', y='AvgRevenue', ax=ax, label=name)
我通过将设备['Month']转换为日期时间来解决问题:
device['Month'] = pd.to_datetime(device['Month'], format='%Y%M')
相关问题 更多 >
编程相关推荐