Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/jenkins/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 删除前x百分位数据后重新采样时间序列_Python 3.x_Pandas - Fatal编程技术网

Python 3.x 删除前x百分位数据后重新采样时间序列

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=

我有一个小时时间序列数据(比如带有日期/时间和值列的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=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