简体   繁体   English

将 5 分钟值转换为 15 分钟值

[英]Convert 5 minutes values to 15 minutes values

I have the following data as Dataframe:我有以下数据 Dataframe:

数据框

As can be seen, the data is available in 5 minute steps.可以看出,数据以 5 分钟为步长可用。 Now i want to convert the 5-min steps to 15-min steps.现在我想将 5 分钟的步骤转换为 15 分钟的步骤。 The columns "Verbrauch (kWh)" and "Leistung" should convert to the mean of the 15-min intervall. “Verbrauch (kWh)”和“Leistung”列应转换为 15 分钟间隔的平均值。

I am able to convert to hourly data with the following:我可以通过以下方式转换为每小时数据:

df.groupby(df["Zeitpunkt"].dt.strftime('%Y-%m-%d %H-')).mean()

But how do i do that with 15min steps?但是我如何用 15 分钟的步骤做到这一点?

first replace "_" with nan:首先用 nan 替换“_”

import numpy as np
df = df.replace('_', np.nan)

then use resample and get means:然后使用resample并获取方法:

df['Zeitpunkt']=pd.to_datetime(df['Zeitpunkt'])
final= df.set_index('Zeitpunkt').sort_index().resample('15Min').agg({'Verbrauch (kWh)':'mean','Leistung':'mean'})

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM