Given this pandas dataframe with three columns, 'room_id', 'temperature' and 'State'. How do I get a forth column 'Max' indicating wehn the value is a maximum for each interval where State is True and for each room ?
117 1.489000 True
8.9 False
2.5 False
4.370000 False
4.363333 True
4.356667 True
118 4.35 True
6.648000 True
6.642667 True
7.3 False
9.4 False
5.3 True
7.1 True
What I am expecting
117 1.489000 True max
8.9 False
2.5 False
4.370000 False
4.363333 True max
4.356667 True
118 4.35 True
6.648000 True max
6.642667 True
7.3 False
9.4 False
5.3 True
7.1 True max
I used this :
Max = df_state.groupby(masque.cumsum()[~masque])['temperature'].agg(['idxmax'])
But I found this :
117 1.489000 True max
8.9 False
2.5 False
4.370000 False
4.363333 True
4.356667 True
118 4.35 True
6.648000 True max
6.642667 True
7.3 False
9.4 False
5.3 True
7.1 True max
I miss the last max of room 117 because the algorithm does not take into account the room id