用法:
class pandas.Timestamp(ts_input=<object object>, freq=None, tz=None, unit=None, year=None, month=None, day=None, hour=None, minute=None, second=None, microsecond=None, nanosecond=None, tzinfo=None, *, fold=None)
python datetime.datetime 對象的 Pandas 替換。
Timestamp 是 python 的 Datetime 的 pandas 等價物,在大多數情況下可以與它互換。它是用於構成 DatetimeIndex 的條目的類型,以及 pandas 中其他麵向時間序列的數據結構。
- ts_input:datetime-like,str,int,float
要轉換為時間戳的值。
- freq:str,日期偏移
時間戳將具有的偏移量。
- tz:str、pytz.timezone、dateutil.tz.tzfile 或無
Timestamp 將具有的時間的時區。
- unit:str
如果 ts_input 是 int 或 float 類型,則用於轉換的單位。有效值為“D”、‘h’, ‘m’, ‘s’, ‘ms’, ‘us’, and ‘ns’。例如,‘s’ 表示秒,‘ms’ 表示毫秒。
- year, month, day:int
- hour, minute, second, microsecond:int,可選,默認0
- nanosecond:int,可選,默認0
- tzinfo:datetime.tzinfo,可選,默認無
- fold:{0, 1},默認無,僅關鍵字
由於夏令時,一個掛鍾時間可以在從夏季時間轉換到冬季時間時出現兩次; fold 說明 datetime-like 是對應於掛鍾的第一次 (0) 還是第二次 (1) 命中模糊時間。
參數:
注意:
構造函數本質上有三種調用約定。主要形式接受四個參數。它們可以通過位置或關鍵字傳遞。
其他兩種形式模仿來自
datetime.datetime
的參數。它們可以通過位置或關鍵字傳遞,但不能混合在一起。例子:
使用主要調用約定:
這將轉換 datetime-like 字符串
>>> pd.Timestamp('2017-01-01T12') Timestamp('2017-01-01 12:00:00')
這將以秒為單位轉換表示 Unix 紀元的浮點數
>>> pd.Timestamp(1513393355.5, unit='s') Timestamp('2017-12-16 03:02:35.500000')
這將以秒為單位和特定時區轉換表示 Unix-epoch 的 int
>>> pd.Timestamp(1513393355, unit='s', tz='US/Pacific') Timestamp('2017-12-15 19:02:35-0800', tz='US/Pacific')
使用模仿
datetime.datetime
API 的其他兩種形式:>>> pd.Timestamp(2017, 1, 1, 12) Timestamp('2017-01-01 12:00:00')
>>> pd.Timestamp(year=2017, month=1, day=1, hour=12) Timestamp('2017-01-01 12:00:00')
相關用法
- 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.replace用法及代碼示例
- Python pandas.Timestamp.round用法及代碼示例
- 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用法及代碼示例
注:本文由純淨天空篩選整理自pandas.pydata.org大神的英文原創作品 pandas.Timestamp。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。