I have a DataFrame with a column of type datetime64[ns]. I want to filter on both year and quarter. Any suggestions on how to do this?
I have tried this cumbersome solution
data = data[(pd.Series(pd.DatetimeIndex(data['MatCalID']).year).isin([2018]) & pd.Series(pd.DatetimeIndex(data['MatCalID']).quarter).isin([2,3]))]
Why this complicated solution?:
- It is necessary to use pd.DatetimeIndex in order to access 'year' and 'quarter'
- It is necessary to use pd.Series to use 'isin'
Unfortunately I get 'Unalignable boolean Series key provided' as an error.
Does someone know how to do this?