I'm building an empty dataframe for a basic calendar table, then populating with pd.date_range values in one column. The problem is the dataframe comes up as empty after append. Here's my code:
def date_calendar(table, startdate, enddate, datefreq):
# create a df
df = pd.DataFrame({
'Year': [],
'FY Year': [],
'Quarter': [],
'MonthNum': [],
'YearMonth': [],
'YearMonthShort': [],
'YearMonthNum': [],
'Date': [],
})
# create a date_range specified in function inputs
per1 = pd.date_range(start=startdate,
end=enddate, freq=datefreq)
# make the date_range into a series because .append method doesn't work if per1 is not a series
per2 = per1.to_series()
# append series to df
df['Date'].append(per2)
return df
date_calendar(table, startdate='1-1-2019', enddate='6-30-2024', datefreq='D')
And my results are:
<bound method NDFrame.head of Empty DataFrame Columns: [Year, FY Year, Quarter, MonthNum, YearMonth, YearMonthShort, YearMonthNum, Date] Index: []>