0

I want to merge two dataframes. However, when I use read_csv function in pandas, the output of date column are different. I try to use df.astype(object) function to convert that column to object but doesnt works. I could not merge these 2 dataframe because the expiryDate column is different.

df1:

symbol.  expiryDate.
AA       20/5/2021

df2:

symbol.  expiryDate.
AA       2021-05-20
janicewww
  • 323
  • 1
  • 10

1 Answers1

0

You can convert the column to datetime dtype using to_datetime, and then proceed to merge the dataframes.

df1['expiryDate'] = pd.to_datetime(df1['expiryDate'], format="%d/%m/%Y"))

Specifying the datetime format is optional, but I suggest that you use it to avoid possible wrongly converted dates.

Alex Metsai
  • 1,837
  • 5
  • 12
  • 24