Site icon Analytics4All

Python: Convert Datetime to Date using Pandas


To convert a datetime in a pandas dataframe to date use the function:

df['column'] = pd.to_datetime(df['column'])

To demonstrate, first let’s build a dataframe

import pandas as pd
df = pd.DataFrame({'Job_Start': ['Demolition','Construction', 'Cleanup'],
                   'time': ['2022-05-20 08:07:22', '2022-05-27 07:34:01', 
                   '2022-06-01 09:12:11']})

Now lets convert the “time” column to date instead of datetime

df['time'] = pd.to_datetime(df['time'])
Exit mobile version