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 
3
  • Does this answer your question? Working with mixed date time formats in pandas Commented Jun 8, 2020 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. Commented Jun 8, 2020 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. Commented Jun 8, 2020 at 10:45

1 Answer 1

2

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

pd.to_datetime(df['date'].astype(str)).dt.date
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.