I am trying to get data for previous year and present year from dataframe using below function.
def get_date(s_year, s_month):
‘’‘Function to get date from year and month
Arg:
(s_year, s_month as <string, int>)
Returns:
date as datetime.date’‘’
dt = pd.to_datetime(int(s_year)*10000+int(s_month)*100+1, format = “%Y%m%d”)
return dt.date()def get_last_day(idt):
‘’‘Function to get the last date of a month
Arg:
idt as date
Returns:
last date as datetime.date
‘’’
dt = pd.to_datetime(idt) + pd.tseries.offsets.MonthEnd(1)
return dt.date()
It is working fine for 2019, 2020 and 2021. but when i changed to 2020 and 2021 and 2022 it is not giving output.
Do i need to change something in function,
Please share your valuable suggestion
Thanks a ton