Remove time portion of DateTime index in pandas

With the date attribute:

df.index = df.index.date

Example:

>>> df = pd.DataFrame([1, 2, 3, 4], index=pd.date_range('2018', periods=4, freq='H'))
>>> df.index = df.index.date
>>> df
            0
2018-01-01  1
2018-01-01  2
2018-01-01  3
2018-01-01  4

Note: that this will get you object dtype in Pandas. All attributes are here. It’s technically an array of native Python datetime.date objects. See ALollz’s answer to keep the dtype datetime-like.

Leave a Comment