I have a column in my DATA in df from which I need to create a new column to extract the last working day of the month or the last day of the month of that specific month.
df = pd.DataFrame({
'DATA':['2021-10-06','2021-10-05','2021-10-04','2021-10-01','2021-09-30','2021-09-29 ','2021-09-28','2021-09-27 ']
})
print(df)
I managed to do this with the help of BMonthEnd() this way.
df['DATA2'] = pd.to_datetime(df['DATA']) + BMonthEnd()
But when I arrive on the last working day of a given month it skips to the following month.
a way to use the last date of that month can be used.
Ex Using BMonthEnd()
DATA DATA2
2021-10-06 2021-10-29
2021-10-05 2021-10-29
2021-10-04 2021-10-29
2021-10-01 2021-10-29
2021-09-30 2021-10-29 ** Erro, Correct = 2021-09-30
2021-09-29 2021-09-30
2021-09-28 2021-09-30
2021-09-27 2021-09-30
is there any way to reolver? can be using another way