How can I reset the time part of a pandas timestamp?
I want to reset time part in value of pandas.Timestamp.
I guess I can do it using the following procedure.
Even if my guess is correct, it takes too long to do. Is there a straightforward way to achieve this goal?
In : ts = pd.Timestamp('2014/11/12 13:35')
In : ts
Out: Timestamp('2014-11-12 13:35:00')
In : ts.hour = 0 # <-- this is what I am trying to do.
I think you are looking for the
replace method (see docs):
In : ts Out: Timestamp('2014-11-12 13:35:00') In : ts.replace(hour=0) Out: Timestamp('2014-11-12 00:35:00')
This is a method inherited from
If you want to reset the full time part, you specify all parts in
In : ts.replace(hour=0, minute=0, second=0) Out: Timestamp('2014-11-12 00:00:00')
There is also a
DatetimeIndex.normalize method, but this isn't available on the individual Timestamps (I opened an issue for that: https://github.com/pydata/pandas/issues/8794):
In : pd.DatetimeIndex([ts]).normalize() Out: Timestamp('2014-11-12 00:00:00')