For match values is possible convert DatetimeIndex
to months periods and test membership by Index.isin
:
#if necessary
#df.index = pd.to_datetime(df.index)
df3 = df[df.index.to_period('m').isin(pd.to_datetime(['2021-06','2021-08']).to_period('m'))]
print (df3)
sales
report_date
2021-06-30 130000
2021-06-30 140000
2021-08-31 110000
2021-08-31 110000
Or:
df3 = df[df.index.to_period('m').isin(pd.PeriodIndex(['2021-06','2021-08'], freq='m'))]
print (df3)
sales
report_date
2021-06-30 130000
2021-06-30 140000
2021-08-31 110000
2021-08-31 110000
Or convert values to strings YYYY-MM
and test by strings in list:
df3 = df[df.index.strftime('%Y-%m').isin(['2021-06','2021-08'])]
print (df3)
sales
report_date
2021-06-30 130000
2021-06-30 140000
2021-08-31 110000
2021-08-31 110000