0

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?

Carbo
  • 906
  • 5
  • 23
  • I am not sure it is clear what you want to achieve and what the expected outcome is. – buran May 17 '21 at 12:53
  • @buran to make an example: for month 3 and group A I have 5 scores: 1,2,3,4,5 I can rescale each of them by applying (40*(x-min(x)))/(max(x)-min(x)) + 60) with min(x) = 1 and max(x) = 5. but I want to rescale those values not just with respect to the values in month 1,2,3. so if for month 1 and type A I have scores 0,3,2 and for month 2 and type A I have scores 3,4,7, the rescaling happening in month 3 should have min(x) = 0 and max(x) = 7 – Carbo May 17 '21 at 12:58

0 Answers0