I have the following dataframe with a tricky problem:
df = pd.DataFrame({'weight': [[200, 190, 188, 180, 170],
[181, 175, 172, 165, 150]],
'days_since_gym': [[0, 87, 174, 205, 279],
[43, 171, 241, 273, 300]]})
print(df)
weight days_since_gym
0 [200, 190, 188, 180, 170] [0, 91, 174, 205, 279]
1 [181, 175, 172, 165, 150] [93, 171, 241, 273, 300]
I have to make 4 columns (0-90 days, 91-180 days, 181-270 days, 271-360 days) based on the following conditions:
1) If there are multiple weights in a specific time duration, get the maximum weight in that time duration column.
2) If no weight is present in that time duration, the value for that duration would be 0.
Desired output:
weight days_since_gym 0-90 91-180 181-270 271-360
0 [200, 190, 188, 180, 170] [0, 87, 174, 205, 279] 200 188 180 170
1 [181, 175, 172, 165, 150] [93, 171, 241, 273, 300] 0 181 172 165
What would be the smartest way of doing it? Any suggestions would be appreciated. Thanks!