我有一个时间序列,我想将不同的函数应用于同一列。
主要栏目是重量。我想创建一个df,它显示重采样周期中权重的均值加上最大值。我知道我能做到:
df.resample('M', how = {'weight':np.max}, kind='YearEnd')
df1.resample('M', how = {'weight': np.mean}, kind='YearEnd')
这似乎效率低下。
优化:
df.resample('M', how = {'weight': np.mean, 'weight':np.max}, kind='YearEnd')
答案 0 :(得分:3)
试试这个。
In [23]: df = DataFrame(np.random.randn(100,1),columns=['weight'],index=date_range('20000101',periods=100,freq='MS'))
In [24]: df.resample('A',how=['max','mean'])
Out[24]:
weight
max mean
2000-12-31 1.958570 -0.312230
2001-12-31 1.739518 0.035701
2002-12-31 2.503437 0.169365
2003-12-31 1.115315 0.149279
2004-12-31 2.190617 -0.087536
2005-12-31 1.286224 0.037669
2006-12-31 1.674017 0.147676
2007-12-31 2.107169 -0.064962
2008-12-31 -0.163863 -0.572363
[9 rows x 2 columns]
支持如何作为一个我认为不太难的词典,将会提出有关此增强功能的问题:https://github.com/pydata/pandas/issues/6515