0

I have the following table, already grouped by. I want to keep only the rows with the latest date. I am using Pandas.

The result below came from this code.

df = df.sort_values(by=['Type', 'Date'],ascending=[True,False]) df.groupby(['Type','Date','Code'])

Type Date Code
XXX 16/02/2023 123
245
485
15/02/2023 123
542
658
YYY 16/02/2023 987
642
582
15/02/2023 425
555
666

In the and I want like these:

Type Date Code
XXX 16/02/2023 123
245
485
YYY 16/02/2023 987
642
582

Already tried everything and nothing gives me the result I want. Any one have an idea?

0 Answers0