重新采样并插入pandas df

时间:2018-06-10 18:29:56

标签: pandas interpolation

我的df如下所示:

TotalSpend   Date
  100    2001-04-26
  230    2001-05-12
  340    2001-06-16
  610    2001-07-31
  770    2001-08-31

我正在尝试插入数据,以便我可以看到每个月花了多少钱:

TotalSpend   Date     MonthlySpend
  110    2001-04-30      
  310    2001-05-31      200
  400    2001-06-30      90
  610    2001-07-31      210
  770    2001-08-31      160

我将日期列设置为索引,并尝试对数据进行上采样(下图),以便我每年都有一天,然后可以插入缺失的值并选择月末,但这很麻烦。

       resample = realdf.resample('d').mean()

非常感谢任何帮助。

0 个答案:

没有答案
相关问题