Thursday 15 March 2012

python - Reset time part of a pandas timestamp -



python - Reset time part of a pandas timestamp -

how can reset time part of pandas timestamp?

i want reset time part in value of pandas.timestamp. guess can using next procedure.

step 1) timestamp datetime type step 2) datetime seconds step 3) truncate time part in seconds step 4) bring seconds timestamp

even if guess correct, takes long do. there straightforward way accomplish goal?

in [371]: ts = pd.timestamp('2014/11/12 13:35')

in [372]: ts

out[372]: timestamp('2014-11-12 13:35:00')

in [373]: ts.hour = 0 # <-- trying do.

i think looking replace method (see docs):

in [18]: ts out[18]: timestamp('2014-11-12 13:35:00') in [19]: ts.replace(hour=0) out[19]: timestamp('2014-11-12 00:35:00')

this method inherited datetime.datetime

if want reset total time part, specify parts in replace:

in [20]: ts.replace(hour=0, minute=0, second=0) out[20]: timestamp('2014-11-12 00:00:00')

there datetimeindex.normalize method, isn't available on individual timestamps (i opened issue that: https://github.com/pydata/pandas/issues/8794):

in [21]: pd.datetimeindex([ts]).normalize()[0] out[21]: timestamp('2014-11-12 00:00:00')

python datetime pandas timestamp

No comments:

Post a Comment