如何根据Datetimeindex在大熊猫数据框中每月重新采样

问题描述

furniture = furniture.groupby('Order Date')['Sales'].sum().reset_index()
print(furniture.head())

输出

  Order Date     Sales
0 2014-01-06  2573.820
1 2014-01-07    76.728
2 2014-01-10    51.940
3 2014-01-11     9.940
4 2014-01-13   879.939

当我想获得每月销售平均值时,请添加

y = furniture['Sales'].resample('MS').mean()

输出

TypeError: Only valid with DatetimeIndex,timedeltaIndex or Periodindex,but got an instance of 'RangeIndex'

我可以理解我的“订购日期”列不是时间戳格式的,我不知道如何转换。

有什么想法吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)