df1['3DaysMaxHigh']=df1['High'].rolling(window=3).max().shift()
df1['Daysfrom3DayMaxHigh']=('NaN','NaN','NaN',3,1,1,2,3)
Date High 3DaysMaxHigh Daysfrom3DayMaxHigh
2021-05-03 1361.000000 NaN NaN
2021-05-04 1354.949951 NaN NaN
2021-05-05 1343.900024 NaN NaN
2021-05-06 1364.699951 1361.000000 3
2021-05-07 1373.050049 1364.699951 1
2021-05-10 1352.900024 1373.050049 1
2021-05-11 1341.000000 1373.050049 2
2021-05-12 1330.000000 1373.050049 3
The values of column 'Daysfrom3DayMaxHigh' are to be filled with code. For each value in column '3DaysMaxHigh', no of days passed since the occurrence from that max High value in column 'High' should be extracted into column 'Daysfrom3DayMaxHigh'.
In Excel the same was possible with match()
function.