0

I have a DataFrame :

Age Gender Address     Date
15    M    172 ST   2022-02-07 00:00:00 

I Want to remove hh:mm:ss I tried:

import datetime as dt
df["Date"]=df["Date"].dt.Date .

But I am receiving no change in date column format.

All I want is that the date column has only (YYYY-MM-DD).

4
  • How about df["Date"]=df["Date"].dt.date? Commented May 6, 2022 at 17:55
  • 1
    unfortunately this doesnt work Commented May 6, 2022 at 17:59
  • What's the result of df.dtypes. Commented May 6, 2022 at 18:01
  • 1
    everything is an object Commented May 6, 2022 at 18:04

1 Answer 1

0

You can use pd.to_datetime to convert Date column to datetime object.

df['Date'] = pd.to_datetime(df['Date']).dt.date
# or
df['Date'] = pd.to_datetime(df['Date']).dt.strftime('%Y-%m-%d')
# or
df['Date'] = df['Date'].str.split(' ').str[0]
Sign up to request clarification or add additional context in comments.

Comments