I'm facing a problem with filtered dataframe and groupby
Say I have this dataframe
id product date 0 220 6647 2015-09-01 1 220 6647 2014-09-03 2 220 6647 2014-10-16 3 826 3380 2014-11-11 4 826 3380 2015-12-09 5 826 3380 2015-05-19 6 901 4555 2015-09-01 7 901 4555 2014-10-05 8 901 4555 2014-11-01
I'd like to first select rows of year 2015 and then groupby id and get the latest by date
I've read this article, that works great on the entire df
but it seems it's not working if I first try to filter the df like this
my_date = datetime.datetime(2014, 12, 31)
df = df[df.date>my_date]
now if I run the following code
df.loc[df.groupby('id').date.idxmax()]
it gives my the following error
attempt to get argmax of an empty sequence
Any help would be appreciated :) thanks