I currently have a pandas.DataFrame
which has a pandas.DatetimeIndex
and a set of values.
I would like to exclude all the dates in a given pandas.date_range
from this pandas.DataFrame
.
Example code:
dates = pd.date_range(start='04/01/2012', end='04/01/2019', freq='MS')
df = pd.DataFrame(data=[100]*len(dates),index=dates,columns=["val"])
exclusion_dates = pd.date_range(start='04/01/2012', end='04/01/2019', freq=pd.offsets.DateOffset(months=12))
My attempt:
df.loc[~exclusion_dates,:]
Ideally this would lead to df
containing all dates except for 1st April YYYY
However, this leads to the below error:
TypeError: bad operand type for unary ~: 'DatetimeIndex'
I looked at the below thread, however could not find anything: Filtering Pandas DataFrames on dates