Create a Year-Month column
year_month = pd.date_range(start='2020-04', end='2021-09', freq='M')
df = pd.DataFrame({
'pat_id': pat_ids.repeat(len(year_month)),
'year_month': pd.DatetimeIndex(np.tile(year_month, len(pat_ids)))
})
df['year_month'] = df['year_month'].dt.strftime('%Y-%m')
year_month = pd.date_range(start='2020-04', end='2021-09', freq='M')
df = pd.DataFrame({'year_month_end': year_month})
df['year_month_start'] = df['year_month_end'].apply(lambda dt: dt.replace(day=1))
Comments