用法:
Timestamp.replace(year=None, month=None, day=None, hour=None, minute=None, second=None, microsecond=None, nanosecond=None, tzinfo=<class 'object'>, fold=None)
實現 datetime.replace,處理納秒。
- year:整數,可選
- month:整數,可選
- day:整數,可選
- hour:整數,可選
- minute:整數,可選
- second:整數,可選
- microsecond:整數,可選
- nanosecond:整數,可選
- tzinfo:tz-convertible,可選
- fold:整數,可選
- 替換字段的時間戳
參數:
返回:
例子:
創建時間戳對象:
>>> ts = pd.Timestamp('2020-03-14T15:32:52.192548651', tz='UTC') >>> ts Timestamp('2020-03-14 15:32:52.192548651+0000', tz='UTC')
替換年份和小時:
>>> ts.replace(year=1999, hour=10) Timestamp('1999-03-14 10:32:52.192548651+0000', tz='UTC')
替換時區(不是轉換):
>>> import pytz >>> ts.replace(tzinfo=pytz.timezone('US/Pacific')) Timestamp('2020-03-14 15:32:52.192548651-0700', tz='US/Pacific')
類似於
pd.NaT
:>>> pd.NaT.replace(tzinfo=pytz.timezone('US/Pacific')) NaT
相關用法
- Python pandas.Timestamp.round用法及代碼示例
- Python pandas.Timestamp.dayofweek用法及代碼示例
- Python pandas.Timestamp.dayofyear用法及代碼示例
- Python pandas.Timestamp.strftime用法及代碼示例
- Python pandas.Timestamp.month_name用法及代碼示例
- Python pandas.Timestamp.ceil用法及代碼示例
- Python pandas.Timestamp.to_numpy用法及代碼示例
- Python pandas.Timestamp.days_in_month用法及代碼示例
- Python pandas.Timestamp.asm8用法及代碼示例
- Python pandas.Timestamp.is_quarter_end用法及代碼示例
- Python pandas.Timestamp.timestamp用法及代碼示例
- Python pandas.Timestamp.daysinmonth用法及代碼示例
- Python pandas.Timestamp.tz_convert用法及代碼示例
- Python pandas.Timestamp.is_quarter_start用法及代碼示例
- Python pandas.Timestamp.fromordinal用法及代碼示例
- Python pandas.Timestamp.tz用法及代碼示例
- Python pandas.Timestamp.weekofyear用法及代碼示例
- Python pandas.Timestamp.normalize用法及代碼示例
- Python pandas.Timestamp.utcfromtimestamp用法及代碼示例
- Python pandas.Timestamp.week用法及代碼示例
注:本文由純淨天空篩選整理自pandas.pydata.org大神的英文原創作品 pandas.Timestamp.replace。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。