我有下面的数据帧
df
datestamp device country users
2021-01-14 ipad uk 10
2021-01-14 iphone uk 15
2021-01-14 ipad us 20
2021-01-14 iphone us 40
2021-01-14 ipad fr 100
2021-01-14 iphone fr 50
2021-01-15 ipad uk 20
2021-01-15 iphone uk 10
2021-01-15 ipad us 20
2021-01-15 iphone us 60
2021-01-15 ipad fr 300
2021-01-15 iphone fr 500
我想知道
users
每
datestamp device country
df.groupby(['datestamp','country', 'device']).count().pct_change().reset_index()
但它忽略了分组,只是逐行检查。
datestamp device country users change
2021-01-14 ipad uk 10 np.nan
2021-01-14 iphone uk 15 np.nan
2021-01-14 ipad us 20 np.nan
2021-01-14 iphone us 40 np.nan
2021-01-14 ipad fr 100 np.nan
2021-01-14 iphone fr 50 np.nan
2021-01-15 ipad uk 20 100%
2021-01-15 iphone uk 10 -33%
2021-01-15 ipad us 20 0%
2021-01-15 iphone us 60 50%
2021-01-15 ipad fr 300 300%
2021-01-15 iphone fr 500 1000%