Python 日夜对数据帧重新采样

Python 日夜对数据帧重新采样,python,dataframe,Python,Dataframe,我有一个数据框,看起来像: column 2015-01-01 00:00:00 27.38 2015-01-01 01:00:00 23.37 2015-01-01 02:00:00 19.33 2015-01-01 03:00:00 17.66 2015-01-01 04:00:00 17.53 2015-01-01 05:00:00 18.07 2015-01-01 06:00:00 25.23 201

我有一个数据框,看起来像:

                       column
2015-01-01 00:00:00    27.38
2015-01-01 01:00:00    23.37
2015-01-01 02:00:00    19.33
2015-01-01 03:00:00    17.66
2015-01-01 04:00:00    17.53
2015-01-01 05:00:00    18.07
2015-01-01 06:00:00    25.23
2015-01-01 07:00:00    26.80
2015-01-01 08:00:00    26.97
2015-01-01 09:00:00    26.29
以此类推,从2015-01-01 00:00到2017-12-31 23:00每小时

我想重新取样,这样我就得到了“夜间”和“白天”的平均值。我定义晚上18:00到07:00,白天为07:00到18:00。这样就产生了类似于

                     column
2015-01-01 07:00:00    x    (This would be the mean of the values from 2015-01-01 00:00:00 to 2015-01-01 07:00:00)
2015-01-01 18:00:00    x    (This would be the mean of the values from 2015-01-01 07:00:00 to 2015-01-01 18:00:00)
2015-01-02 07:00:00    x    (This would be the mean of the values from 2015-01-01 18:00:00 to 2015-01-02 07:00:00)
2015-01-02 18:00:00    x    (This would be the mean of the values from 2015-01-02 07:00:00 to 2015-01-02 18:00:00)
2015-01-03 07:00:00    x    (This would be the mean of the values from 2015-01-02 18:00:00 to 2015-01-03 07:00:00)
2015-01-03 18:00:00    x    (This would be the mean of the values from 2015-01-03 07:00:00 to 2015-01-03 18:00:00)

我希望我的要求是明确的。如果我需要解释什么,请告诉我

一个简单的解决方法如下:


df[0]=df[0].apply(lambda x:x.split()[0]+'day'if int(x[-8:-6])啊,这假设索引在其单独的列中。这在我的情况下不是真的,但我想我可以做一些解决方法。您可以使用
df.reset_index()重置索引<或代码>。然后应用该方法……如果这个答案有帮助,请考虑它的投票。我的索引是一个DATE时间索引。我得到的错误是“时间戳”对象不是可订阅的。“只是使用<代码>将它转换成字符串。ASPYPE(STR)< /代码>