how to get the last day of the month from a given date
Referring to the above repo, I have a similar question I have a data of number of rows 2107260 and number of columns 8, a snapshot of the data:
Now the issue is that I am trying to have the Date column look like this:
Now what I have done is:
df2_1=pd.read_csv("C:\\Users\\Chirantan.Gupta\\Desktop\\Poland_Project\\V1_Data_SFS_2017_21.csv",low_memory=False)
import calendar
from datetime import timedelta
from datetime import date
df2_1['Date'] = pd.to_datetime(df2_1['Date'], format='%Y-%d-%m')
df2_1['Date']= df2_1['Date'].dt.date
for i in range(df2_1.shape[0]):
df2_1.iloc[i,6]=date(df2_1.iloc[i,6].year + (df2_1.iloc[i,6].month == 12),
(df2_1.iloc[i,6].month + 1 if df2_1.iloc[i,6].month < 12 else 1), 1) - timedelta(1)
The issue is this data being huge takes humongous time to run and as a consequence it is infeasible, in my opinion. My question is: Is there any way I can have this thing done without having the for loop as I have used, I am running out of ideas here, if anyone can help please.