I have a Pandas DataFrame with a \'date\' column. Now I need to filter out all rows in the DataFrame that have dates outside of the next two months. Essentially, I only need
The shortest way to filter your dataframe by date: Lets suppose your date column is type of datetime64[ns]
# filter by single day
df = df[df['date'].dt.strftime('%Y-%m-%d') == '2014-01-01']
# filter by single month
df = df[df['date'].dt.strftime('%Y-%m') == '2014-01']
# filter by single year
df = df[df['date'].dt.strftime('%Y') == '2014']