如何在时间序列上使用Pandas扩展功能

时间:2013-10-27 20:47:05

标签: python-2.7 pandas

理想情况下,我希望它最终会像这样(注意modelIDs组合在一起,expand_mean,expanding_median函数,SaleCount等等):

enter image description here

我尝试对数据进行排序并通过'saledate'重新编制索引,然后使用'group_by'来执行每个modelID的函数,但似乎无法将其转换为所需的格式。我一直在研究看起来应该是相当简单的任务3天。任何建议都将不胜感激。

1 个答案:

答案 0 :(得分:1)

尝试将transformshift结合使用:

from pandas.stats.moments import *

df.groupby(['ModelID', 'saledate']).transform(lambda x: expanding_mean(x.shift(1)))