0

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 
smci
  • 32,567
  • 20
  • 113
  • 146
Biswankar Das
  • 303
  • 4
  • 12
  • Does this answer your question? [Working with mixed date time formats in pandas](https://stackoverflow.com/questions/60390709/working-with-mixed-date-time-formats-in-pandas) – Bertil Johannes Ipsen Jun 08 '20 at 10:37
  • @BertilJohannesIpsen No, the date format is the same across the entire column. Just that a few have time (00:00:00) attached to them .The answer by **jezrael** seems to be working. Will validate and update. – Biswankar Das Jun 08 '20 at 10:45
  • 1
    @BertilJohannesIpsen that's not a relevant dupe target, it;s about multiple *datetime* formats (`YYYY-MM-DD` vs `DD.MM.YYYY`). But this one is about a single date format, except that it may/may not contain the time. – smci Jun 08 '20 at 10:45

1 Answers1

2

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

pd.to_datetime(df['date'].astype(str)).dt.date
jezrael
  • 822,522
  • 95
  • 1,334
  • 1,252