Consider the following DateTimeIndex:
from calendar import monthrange
import pandas as pd
index_h = pd.date_range(start='2022-01-04 00:00:00', end='2023-01-10 23:00:00', freq='H')
We can see that both January/2022 and January/2023 are incomplete.
How can I create a list that contains the Month/Year that are complete in that range?
I have been trying to use monthrange
from calendar
to count the values, but not really sure how to proceed from here:
years_months = index_h.to_period('M').unique()
complete_month_year_list = []
for year_month in years_months:
num_days = monthrange(year_month.year, year_month.month)[1]
if what_goes_here??? == num_days:
print(f"Month {year_month.month} of year {year_month.year} is complete.")
complete_month_year_list.append(?????)
else:
print(f"Month {year_month.month} of year {year_month.year} is not complete.")