I have a df with which can be represented below with a date column and 4 variable columns.
Date A B C D
2015-10-31 6 7 3 7
2015-11-01 1 3 9 4
2015-11-02 4 5 8 1
2015-11-03 4 2 5 9
I am looking to filter the df on the last business day of each month by adding an additional column called 'EndofMonth' and taking the trailing nth row from each month:
df['EndOfMonth'] = pd.to_datetime(df['DATE'], format="%Y%m") + MonthEnd(1)
df.apply(lambda x: x.sort('dt', ascending=True).tail(1))
This is giving me an error. Any ideas on how to better solve this?