# 对温度做分段常数逼近处理,下采样
def constant_appro_low(df_data_by_date_tem):
df_data_by_date_tem = df_data_by_date_tem.reset_index(drop=True)
df_appro = pd.DataFrame()
date_index = pd.date_range(end = '01/01/2019', periods=len(df_data_by_date_tem), freq='D')
temperature = 'Temperature'
date_ymd = 'date_ymd'
df_appro[temperature] = df_data_by_date_tem[temperature]
df_appro.index = date_index
# 下采样,取均值
df_appro_low = pd.DataFrame()
# 一个小时聚合一次常值, 这里通过 6 个数值进行取一次均值,例如:[0, 5] ,[6, 11] , ... 取均值
df_appro_low[temperature] = df_appro[temperature].resample(rule='6D').mean()
#date_list = df_data_by_date_tem.loc[:len(df_appro_low)-1][date_ymd]
#df_appro_low[date_ymd] = list(date_list)
# 差分,做一阶差分
df_appro_diff = pd.DataFrame()
df_appro_diff[temperature] = df_appro_low.loc[:][temperature].diff(1) # 1 阶差分
df_appro_diff[date_ymd] = list(df_data_by_date_tem.loc[:len(df_appro_diff)-1][date_ymd])
df_appro_diff = df_appro_diff.dropna()
df_appro_diff = df_appro_diff.reset_index(drop=True)
df_appro_diff[temperature] = df_appro_diff[temperature].apply(lambda x: round(x, 2))
return df_appro_diff
以上内容可以参考:
上采样、下采样:https://mbd.baidu.com/newspage/data/landingsuper?context={"nid"%3A"news_9661997349921147196"}&n_type=1&p_from=3
差分处理:https://mbd.baidu.com/newspage/data/landingsuper?context={"nid"%3A"news_9532838616696390580"}&n_type=1&p_from=3