小编use*_*943的帖子

熊猫滚动百分位等级

我试图在滚动窗口内按列计算数据的百分位数.

test=pd.DataFrame(np.random.randn(20,3),pd.date_range('1/1/2000',periods=20),['A','B','C'])

test
Out[111]: 
                   A         B         C
2000-01-01 -0.566992 -1.494799  0.462330
2000-01-02 -0.550769 -0.699104  0.767778
2000-01-03 -0.270597  0.060836  0.057195
2000-01-04 -0.583784 -0.546418 -0.557850
2000-01-05  0.294073 -2.326211  0.262098
2000-01-06 -1.122543 -0.116279 -0.003088
2000-01-07  0.121387  0.763100  3.503757
2000-01-08  0.335564  0.076304  2.021757
2000-01-09  0.403170  0.108256  0.680739
2000-01-10 -0.254558 -0.497909 -0.454181
2000-01-11  0.167347  0.459264 -1.247459
2000-01-12 -1.243778  0.858444  0.338056
2000-01-13 -1.070655  0.924808  0.080867
2000-01-14 -1.175651 -0.559712 -0.372584
2000-01-15 -0.216708 -0.116188  0.511223
2000-01-16  0.597171  0.205529 -0.728783
2000-01-17 -0.624469  0.592436  0.832100
2000-01-18  0.259269  0.665585  0.126534
2000-01-19 …
Run Code Online (Sandbox Code Playgroud)

python apply rank percentile pandas

7
推荐指数
1
解决办法
3966
查看次数

在 Pandas 中使用“月末减去 t 天”偏移量每天到每月重新采样

我在熊猫数据框中有每日时间序列数据。我需要使用与标准月末频率不同的偏移量将其重新采样为每月。

dates = pd.date_range('2016-09-01', '2017-01-10')
df = pd.DataFrame(data=[x for x in range(len(dates))],index=dates,columns=['MyData'])
Run Code Online (Sandbox Code Playgroud)

我可以使用月末频率进行月度系列:

df_monthly = df.resample('M').last()

df_monthly
Out[78]: 
            MyData
2016-09-30      29
2016-10-31      60
2016-11-30      90
2016-12-31     121
2017-01-31     131
Run Code Online (Sandbox Code Playgroud)

如果 Month End = 'M',我想为 'M-15'、...'M-2'、'M-1'、'M'、'M+1'、M+ 设置类似的月度切片2',...'M+15'。最终,我计划将这些组合成一个列名为“M+T”的数据框。

在 pd.DataFrame.resample() 或 pd.DataFrame.asfreq() 中是否有一种简单的方法可以做到这一点?

python dataframe pandas

4
推荐指数
1
解决办法
7034
查看次数

标签 统计

pandas ×2

python ×2

apply ×1

dataframe ×1

percentile ×1

rank ×1