df=pd.read_csv('https://raw.githubusercontent.com/amanaroratc/hello-world/master/test_df.csv')
id rank date
1991513 FCWFKZVFAHFK7WP4 32 2021-06-01
1991514 FCWEUHFSM2BSQY2N 33 2021-06-01
1991515 FCWFV6T2GGPM8T2P 34 2021-06-01
1991516 FCWEQ8B4QDJJUNEH 35 2021-06-01
1991517 FCWFAUSPJFGDUBRG 36 2021-06-01
I have the above data for 1 month and I want to create a new column delta_rank_7 which tells me the change in rank in last 7 days for each id (NaNs for 2021-06-01 to 2021-06-07)
I can do something like mentioned here Calculating difference between two rows in Python / Pandas
df.set_index('date').diff(periods=7)
but I have multiple entries for each date and I want to do this for each id.