请考虑以下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')
我们可以看到,2022年1月和2023年1月都是不完整的.
如何创建包含该范围内完整的月/年的列表?
我一直在try 使用calendar
中的monthrange
来计算这些值,但不确定如何从下面开始:
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.")