I have the following data frame.
ID Date1 Date2
1 7-12-2021 20-11-2021
1 10-11-2021 01-12-2021
2 22-10-2021 03-12-2021
My idea is based on duplicate value of the ID column compare the two dates and keep the row if Date2 is earlier than Date1. If the value of ID is unique, no need to do comparison and keep the value as it is.
I would like to get the following output.
ID Date1 Date2
1 10-11-2021 01-12-2021
2 22-10-2021 03-12-2021
I have tried this like the following but not succeed.
df = df.groupby(['ID'])[(df['Date1']) < (df['Date2'])]
Can any one help me with this?