1

Existing Dataframe :

Id          group             date
1             A            02/03/2022
1             A            04/02/2022
1             A            01/03/2022
1             B            13/02/2022
1             B            11/02/2022
1             B            18/02/2022
2             A            01/01/2022
2             A            03/01/2022

Expected Output :

Id         A_min             A_max            B_min            B_max  
1       04/02/2022         02/03/2022       11/02/2022       18/02/2022 
2       01/01/2022         03/01/2022           -                -

Within the Id for each group I am trying to find Min and Max date.

tried below approach for respective group but its not giving what's expected

df_1 = df['group'].where(df['group'].eq('A')).groupby(df['Id']).agg({'date': [np.min, np.max]})

df_2 = df['group'].where(df['group'].eq('B')).groupby(df['Id']).agg({'date': [np.min, np.max]})

Any leads..?

Romi
  • 181
  • 7

0 Answers0