| date | name | completed | |
|---|---|---|---|
| aaa@xyz.com | 01-07-2022 12:40:00 | james | no |
| aaa@xyz.com | 01-07-2022 12:10:00 | james | yes |
| aaa@xyz.com | 01-07-2022 12:19:00 | james | yes |
| aaa@xyz.com | 01-07-2022 12:30:00 | james | no |
| bbb@xyz.com | 02-07-2022 08:04:00 | clark | yes |
| bbb@xyz.com | 02-07-2022 08:08:00 | clark | yes |
| bbb@xyz.com | 02-07-2022 08:13:00 | clark | no |
| bbb@xyz.com | 02-07-2022 08:28:00 | clark | no |
In the above dataframe, i want to drop multiple rows associated with name/email-id and retain the earliest time.
Output
| date | name | completed | |
|---|---|---|---|
| aaa@xyz.com | 01-07-2022 12:10:00 | james | yes |
| aaa@xyz.com | 01-07-2022 08:04:00 | clark | yes |
This is what i have tried;
df = df.sort_values('date')
df = df.groupby('date').first()
This ends up creating date as an index. I don't want the column i am sorting on to be created as an index, i want to sort in place. Basically, i want to get the earliest 'date' for each name and email. Both 'name' and 'email' columns have duplicate values, the only differentiating factor is the values in the 'date' column. Out of all the values in the 'date' column for a particular person, i want to only retain the earliest date when completed = 'yes' and drop all the other rows.