I have a pandas dataframe with date index. The df is grouped by date and looks like this:
date ID time_spent
22-04-2021 ABC 60
22-04-2021 XYZ 50
22-04-2021 PQR 55
23-04-2021 XYZ 40
23-04-2021 ABC 70
23-04-2021 XYZ 95
24-04-2021 ABC 15
24-04-2021 DEF 45
24-04-2021 PQR 65
what I need is to create a new column tracking the time spent by each user some (eg. 3) days ago (this part needs to be flexible please). Desired result:
date ID time_spent New_col
22-04-2021 ABC 60 NaN
22-04-2021 XYZ 50 NaN
22-04-2021 PQR 55 NaN
23-04-2021 XYZ 40 NaN
23-04-2021 ABC 70 NaN
23-04-2021 XYZ 95 NaN
24-04-2021 ABC 15 60
24-04-2021 DEF 45 NaN
24-04-2021 PQR 65 55
Could someone please help me? Please bear with me if this is an elementary question, I am new to Pandas.