【发布时间】:2019-02-24 21:32:09
【问题描述】:
我有以下数据生成的数据框:
df2 = df.groupby(['City','Address','date_time'])['house_price'].mean().pct_change()
City Address Date Pct Ch
Washington, D.C. 111 S Street Appletown 2018-08-03 0.298077
2018-08-11 0.000000
2018-08-17 0.000000
2018-09-07 0.000000
2018-09-17 0.000000
2018-09-20 0.000000
222 S Street Appletown 2018-08-07 0.125926
2018-08-11 0.000000
2018-08-17 0.000000
2018-09-07 0.000000
2018-09-17 0.000000
2018-09-20 0.000000
我想删除每个组中的最短日期(2018-08-03 用于 111 S Street Appletown;2018-08-07 用于 222 S Street)。
我试过了
df2 = df.groupby(['City','Address','date_time'])['house_price'].mean().pct_change().filter(lambda x: x['date_time']> x['date_time'].min())
但这会引发错误。有什么好办法吗?
【问题讨论】:
标签: python pandas lambda pandas-groupby