-1

The date column from the data frame df is in this format:

2018-12-20 19:30:00

But I want to create a column that will only contain the dates without the time

2018-12-20

How should I extract the dates only?

1 Answers1

1

You can use .dt function

 df['just_date'] = df['date_&_time'].dt.date

The above returns a datetime.date dtype, if you want to have a datetime64 then you can just normalize the time component to midnight so it sets all the values to 00:00:00:

df['normalised_date'] = df['dates'].dt.normalize()

This keeps the dtype as datetime64 but the display shows just the date value.

Javin
  • 124
  • 5