I have a data frame that looks like this:
date score type
2020-01-01 1 a
2020-04-01 0 a
2020-01-01 3 a
2020-04-01 2 a
2020-11-01 3 b
2019-12-01 4 b
2020-01-01 4 b
If I want to rescale the column score from 60 to 100 for each type and for each date I can easily do as follows:
df['score_rescaled'] = df.groupby(['date', 'type'])['score'].apply(lambda x: (40*(x-min(x)))/(max(x)-min(x)) + 60)
how ever I would like to rescale the column score from 60 to 100 for each type for each date rescaling using not only the values for the single date, but value for each date up to the date:
so for instance for date 2020-01-01 I want to rescale the values at 2020-01-01 using all the scores from month 2020-01-01 and 2019-12-01
for date 2020-04-01 I want to rescale scores in 2020-04-01 using scores from month 2020-01-01, 2019-12-01 and 2020-04-01 etc.
how can I do?