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
(s_year, s_month as <string, int>)
date as datetime.date’’’
dt = pd.to_datetime(int(s_year)*10000+int(s_month)*100+1, format = “%Y%m%d”)
‘’‘Function to get the last date of a month
idt as date
last date as datetime.date
dt = pd.to_datetime(idt) + pd.tseries.offsets.MonthEnd(1)
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