Python 3.x 删除前x百分位数据后重新采样时间序列
我有一个小时时间序列数据(比如带有日期/时间和值列的df),我想: 步骤1:删除每天前5个百分位数 步骤2:获取每天的最大值(步骤1) 步骤3:获得每个月的平均值(步骤2) 以下是我尝试实现上述逻辑的内容:Python 3.x 删除前x百分位数据后重新采样时间序列,python-3.x,pandas,Python 3.x,Pandas,我有一个小时时间序列数据(比如带有日期/时间和值列的df),我想: 步骤1:删除每天前5个百分位数 步骤2:获取每天的最大值(步骤1) 步骤3:获得每个月的平均值(步骤2) 以下是我尝试实现上述逻辑的内容: step_1 = df.resample('D').apply(lambda x: x<x.quantile(0.95)) step_2 = step_1.resample('D').max() step_3 = step_2.resample('M').mean() step_1=
step_1 = df.resample('D').apply(lambda x: x<x.quantile(0.95))
step_2 = step_1.resample('D').max()
step_3 = step_2.resample('M').mean()
step_1=df.resample('D').apply(lambda x:x您就快到了。您的step_1
是一系列布尔值,其索引与原始数据相同,您可以使用它来过滤数据帧,因此:
step_1=df.resample('D').apply(lambda x:x您的第一步是布尔掩码,因此需要添加一个额外的步骤:
将numpy导入为np
作为pd进口熊猫
df=pd.DataFrame(np.random.randn(1000),index=pd.date\u范围(start='1/1/2019',periods=1000,freq='H'),columns=['my\u data']
掩码=df.重采样('D')。应用(λx:x