removing time from date&time variable in pandas?

Assuming all your datetime strings are in a similar format then just convert them to datetime using to_datetime and then call the dt.date attribute to get just the date portion:

In [37]:

df = pd.DataFrame({'date':['2015-02-21 12:08:51']})
df
Out[37]:
                  date
0  2015-02-21 12:08:51
In [39]:

df['date'] = pd.to_datetime(df['date']).dt.date
df
Out[39]:
         date
0  2015-02-21

EDIT

If you just want to change the display and not the dtype then you can call dt.normalize:

In[10]:
df['date'] = pd.to_datetime(df['date']).dt.normalize()
df

Out[10]: 
        date
0 2015-02-21

You can see that the dtype remains as datetime:

In[11]:
df.dtypes

Out[11]: 
date    datetime64[ns]
dtype: object

Leave a Comment