In group 3, I want to get the max value of group 1
In group 5, I want to get the max value of group 3
Input:
import pandas as pd
A=[20,13,15,25,24,13,14,19,13,11]
group=[1,1,2,2,2,3,3,4,4,5]
df=pd.DataFrame({'A':A,'group':group})
Expected Output
A group g_max g-2_max
0 20 1 20
1 13 1 20
2 15 2 25
3 25 2 25
4 24 2 25
5 13 3 14 20
6 14 3 14 20
7 19 4 19 25
8 13 4 19 25
9 11 5 11 14