将 15 分钟数据月份配置文件重新采样为平均日配置文件

Resample 15 min data month profile into an average day profile

我有一个数据框,其中包含整个月每天 15 分钟的数据。其中 DateTime 列是时间戳数据类型,数据框如下所示:

DateTime, Temperature, Moisture, Accumulated precipitation

1/01/2022 00:00, 23, 50, 2,
1/01/2022 00:15, 22, 45, 1,
1/01/2022 00:30, 20, 39, 0,
1/01/2022 01:00, 25, 34, 0,
1/01/2022 01:15, 23, 50, 0,
.
.
.
31/01/2022 00:00, 23, 45, 0,
31/01/2022 00:15, 22, 45, 1,
31/01/2022 00:30, 20, 39, 0,
31/01/2022 01:00, 25, 34, 0,

因此,我怎样才能对数据帧重新采样以获得整个月每 15 分钟数据的平均值?。 12 月的预期结果应为:

DateTime Temperature
00.00 18.4
00:15 15.4
00:30 16.5
.
.
.
23:45 15.0

您可以创建一个名为 'time' 的新列,方法是将时间与 'DateTime' 列分开,然后对 'time' 列执行平均分组。例如:

import numpy as np
import pandas as pd

np.random.seed(42)
df = pd.DataFrame({
    'DateTime':pd.date_range('1/1/2000', periods=4*24*30, freq='15min'),
    'Temperature':np.random.uniform(low=0.0, high=100.0, size=4*24*30),
    'Moisture':np.random.uniform(low=0.0, high=100.0, size=4*24*30)
})
df['Time'] = df['DateTime'].dt.time
result = df.groupby('Time').mean().reset_index() 

输出:

>>> result
        Time  Temperature   Moisture
0   00:00:00    53.906354  49.702393
1   00:15:00    58.617754  46.533957
2   00:30:00    42.697347  47.283152
3   00:45:00    48.215645  46.413589
4   01:00:00    51.422462  51.100578
..       ...          ...        ...
91  22:45:00    42.881353  43.369940
92  23:00:00    48.179361  54.289938
93  23:15:00    46.109330  48.163814
94  23:30:00    53.840951  62.281667
95  23:45:00    58.671288  43.572069