Have a df like that:
id state date
21 Attivato 05/07/2015
21 Cessato 02/22/2015
I'd like to have a dataframe with only row with max date in it. How can it be performed?
Find the most recent date:
recent_date = df['date'].max()
And then get the dataframe with the recent date:
df[df['date'] == recent_date]
To get the row with Top n dates (say top 2 dates),
top_2 = df['date'].nlargest(2)
df[df['date'].isin(top_2)]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With