Movatterモバイル変換


[0]ホーム

URL:


Skip to main content
Ctrl+K

pandas.Timestamp.replace#

Timestamp.replace(year=None,month=None,day=None,hour=None,minute=None,second=None,microsecond=None,nanosecond=None,tzinfo=<class'object'>,fold=None)#

Implements datetime.replace, handles nanoseconds.

Parameters:
yearint, optional
monthint, optional
dayint, optional
hourint, optional
minuteint, optional
secondint, optional
microsecondint, optional
nanosecondint, optional
tzinfotz-convertible, optional
foldint, optional
Returns:
Timestamp with fields replaced

Examples

Create a timestamp object:

>>>ts=pd.Timestamp('2020-03-14T15:32:52.192548651',tz='UTC')>>>tsTimestamp('2020-03-14 15:32:52.192548651+0000', tz='UTC')

Replace year and the hour:

>>>ts.replace(year=1999,hour=10)Timestamp('1999-03-14 10:32:52.192548651+0000', tz='UTC')

Replace timezone (not a conversion):

>>>importpytz>>>ts.replace(tzinfo=pytz.timezone('US/Pacific'))Timestamp('2020-03-14 15:32:52.192548651-0700', tz='US/Pacific')

Analogous forpd.NaT:

>>>pd.NaT.replace(tzinfo=pytz.timezone('US/Pacific'))NaT

[8]ページ先頭

©2009-2025 Movatter.jp