1 回答
TA贡献1900条经验 获得超5个赞
df = pd.DataFrame({'start_date':['2020-09-21','2020-09-21','2020-09-28', '2020-09-28'],
'end_date':['2020-09-27', '2020-09-27', '2020-10-04', '2020-10-04'],
'Country':['Russia', 'India','Russia','India'],
'orders':[150,80,100,120]})
df['start_date'] = pd.to_datetime(df['start_date'])
df.sort_values(by='start_date', inplace=True)
df['% Change'] = df.groupby('Country')['orders'].pct_change()
输出
start_date end_date Country orders % Change
0 2020-09-21 2020-09-27 Russia 150 NaN
1 2020-09-21 2020-09-27 India 80 NaN
2 2020-09-28 2020-10-04 Russia 100 -0.333333
3 2020-09-28 2020-10-04 India 120 0.500000
添加回答
举报