import pandas as pd
Working with datetimes
To extract just date from a full datetime
= pd.Series(pd.date_range("20130101", periods=4, freq='H'))
s s
0 2013-01-01 00:00:00
1 2013-01-01 01:00:00
2 2013-01-01 02:00:00
3 2013-01-01 03:00:00
dtype: datetime64[ns]
Keep just the date:
s.dt.date
0 2013-01-01
1 2013-01-01
2 2013-01-01
3 2013-01-01
dtype: object
Keep just the date as datetime object:
'datetime64') s.dt.date.astype(
0 2013-01-01
1 2013-01-01
2 2013-01-01
3 2013-01-01
dtype: datetime64[ns]
Keep just the date by resetting the timestamp:
s.dt.normalize()
0 2013-01-01
1 2013-01-01
2 2013-01-01
3 2013-01-01
dtype: datetime64[ns]
Keep the date with a particular formatting:
"%Y/%m/%d") s.dt.strftime(
0 2013/01/01
1 2013/01/01
2 2013/01/01
3 2013/01/01
dtype: object