Biswankar Das
Biswankar Das

Reputation: 305

How to clean Pandas data frame column which contains mix of both datetime and date?

I have a column in a Pandas data frame that has a date column but has datetime and date mixed in together as follows:

2020-05-20 00:00:00
2020-05-21 00:00:00
2020-05-22 
2020-05-23 

Is there any way to convert everything to a date format as follows:

2020-05-20 
2020-05-21 
2020-05-22 
2020-05-23 

Upvotes: 0

Views: 474

Answers (1)

jezrael
jezrael

Reputation: 862791

Convert values to strings and then to datetimes, last to dates:

pd.to_datetime(df['date'].astype(str)).dt.date

Upvotes: 2

Related Questions