I am trying to get the next month first date based on billDate in a dataframe.
I did this:
import pandas as pd import datetime from datetime import timedelta dt = pd.to_datetime('15/4/2019', errors='coerce') print(dt) print((dt.replace(day=1) + datetime.timedelta(days=32)).replace(day=1)) It is working perfectly, and the output is :
2019-04-15 00:00:00 2019-05-01 00:00:00 Now, I am applying same logic in my dataframe in the below code
df[comNewColName] = (pd.to_datetime(df['billDate'], errors='coerce').replace(day=1) + datetime.timedelta(days=32)).replace(day=1) But I am getting error like this:
---> 69 df[comNewColName] = (pd.to_datetime(df['billDate'], errors='coerce').replace(day=1) + datetime.timedelta(days=32)).replace(day=1) 70 '''print(df[['billDate']])''' 71 '''df = df.assign(Product=lambda x: (x['Field_1'] * x['Field_2'] * x['Field_3']))''' TypeError: replace() got an unexpected keyword argument 'day'
pandas.Series.replace, notdatetime.datetime.replaceorpandas.Timestamp.replace.