pandas.Timestamp#

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)#

PANDA替换了PYTHON DATETIME.DATETIME对象。

TIMESTAMP等同于PYTHON的DATETIME,在大多数情况下可以与之互换。它是组成DatetimeIndex和Pandas中其他面向时间序列的数据结构的条目所使用的类型。

参数
ts_input类日期时间、字符串、整型、浮点型

要转换为时间戳的值。

freq字符串、日期偏移量

时间戳将具有的偏移量。

tzStr、pytz.timezone、Dateutil.tz.tz文件或无

时间戳将具有的时间的时区。

unit应力

TS_INPUT为int或Float类型时用于转换的单位。有效值为‘D’、‘h’、‘m’、‘s’、‘ms’、‘us’和‘ns’。例如,‘s’表示秒,‘ms’表示毫秒。

年、月、日集成
时、分、秒、微秒整型,可选,默认为0
nanosecond整型,可选,默认为0
tzinfo日期时间.tzinfo,可选,默认为无
fold{0,1},默认无,仅关键字

由于夏令时,一个挂钟时间在从夏季时间转换到冬季时间时可以出现两次;Fold描述类似日期时间的时间是否对应于第一次(0)或第二次(1)挂钟命中不明确的时间。

1.1.0 新版功能.

注意事项

构造函数本质上有三个调用约定。主表单接受四个参数。可以按位置传递,也可以按关键字传递。

其他两种形式模仿中的参数 datetime.datetime 。它们可以通过位置或关键字传递,但不能混合在一起。

示例

使用主要呼叫约定:

这将转换类似DateTime的字符串

>>> 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纪元的int

>>> pd.Timestamp(1513393355, unit='s', tz='US/Pacific')
Timestamp('2017-12-15 19:02:35-0800', tz='US/Pacific')

使用其他两种形式模拟用于 datetime.datetime

>>> 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')

属性

asm8 

返回NumPy DateTime64格式,单位为纳秒。

day_of_week 

一周中的返回日。

day_of_year 

返回一年中的某一天。

dayofweek 

一周中的返回日。

dayofyear 

返回一年中的某一天。

days_in_month 

返回该月的天数。

daysinmonth 

返回该月的天数。

freqstr 

返回该月的总天数。

is_leap_year 

如果年份是闰年,则返回True。

is_month_end 

如果Date是每月的最后一天,则返回True。

is_month_start 

如果Date是每月的第一天,则返回True。

is_quarter_end 

如果日期是季度的最后一天,则返回True。

is_quarter_start 

如果Date是季度的第一天,则返回True。

is_year_end 

如果Date是一年的最后一天,则返回True。

is_year_start 

如果Date是一年的第一天,则返回True。

quarter 

返回一年中的季度。

tz 

Tzinfo的别名。

week 

返回一年中的第几周。

weekofyear 

返回一年中的第几周。

day

fold

freq

hour

microsecond

minute

month

nanosecond

second

tzinfo

value

year

方法:

astimezone \(TZ)

将支持时区的时间戳转换为另一个时区。

ceil \(频率 [, ambiguous, nonexistent] )

返回一个新的时间戳,该时间戳与此解析相同。

combine \(日期、时间)

将日期、时间合并为具有相同日期和时间字段的日期时间。

ctime 

返回ctime()样式字符串。

date 

返回年、月、日相同的日期对象。

day_name 

返回指定地区的时间戳的日期名称。

dst 

返回self.tzinfo.dst(Self)。

floor \(频率 [, ambiguous, nonexistent] )

返回一个新的时间戳,该时间戳已覆盖到此分辨率。

fromisocalendar 

Int,int,int->从ISO年份、周数和星期构建一个日期。

fromisoformat 

字符串->来自日期时间.isFormat()输出的日期时间

fromordinal \(序号[, freq, tz] )

传递一个序数,将其翻译并转换为T。

fromtimestamp \(ts)

转换时间戳 [, tz] 从POSIX时间戳转换为TZ的本地时间。

isocalendar 

返回包含ISO年、周号和工作日的命名元组。

isoformat 

返回根据ISO 8610格式化的时间。

isoweekday \()

返回由该日期表示的星期几。

month_name 

返回指定地区的时间戳的月份名称。

normalize 

将时间戳标准化为午夜,保留tz信息。

now \([tz] )

返回新的Timestamp对象,表示tz本地的当前时间。

replace \([year, month, day, hour, minute, ...] )

实现日期时间。替换,处理纳秒。

round \(频率 [, ambiguous, nonexistent] )

将时间戳四舍五入为指定的分辨率。

strftime \(格式)

返回一个字符串,该字符串表示由显式格式字符串控制的给定POSIX时间戳。

strptime \(字符串,格式)

功能未实现。

time 

返回时间相同但tzinfo=None的Time对象。

timestamp 

以浮点形式返回POSIX时间戳。

timetuple 

返回时间元组,与time.localtime()兼容。

timetz 

返回具有相同时间和tzinfo的Time对象。

to_datetime64 

返回一个精度为‘ns’的numpy.datetime64对象。

to_julian_date \()

将时间戳转换为儒略日期。

to_numpy 

将时间戳转换为NumPy日期64。

to_period 

返回此时间戳为其观察值的时段。

to_pydatetime 

将时间戳对象转换为本机Python DateTime对象。

today \(CLS[, tz] )

返回本地时区中的当前时间。

toordinal 

返回服用安慰剂的格里高利序号。

tz_convert \(TZ)

将支持时区的时间戳转换为另一个时区。

tz_localize \(TZ[, ambiguous, nonexistent] )

将原始时间戳转换为本地时区,或从支持时区的时间戳中删除时区。

tzname 

返回self.tzinfo.tzname(Self)。

utcfromtimestamp \(ts)

从POSIX时间戳构造一个简单的UTC日期时间。

utcnow \()

返回表示UTC日期和时间的新时间戳。

utcoffset 

返回self.tzinfo.utcofset(Self)。

utctimetuple 

返回UTC时间元组,与time.localtime()兼容。

weekday \()

返回由该日期表示的星期几。