在哪里可以找到可接受的pandas.timestamp格式的完整列表?
我发现pandas.timestamp是非常强大且灵活的解析工具,可以接受各种时间戳/日期时间格式。例如,
In [38]: pd.Timestamp('2020')
Out[38]: Timestamp('2020-01-01 00:00:00')
In [39]: pd.Timestamp('2020-02')
Out[39]: Timestamp('2020-02-01 00:00:00')
In [40]: pd.Timestamp('2020Q1')
Out[40]: Timestamp('2020-01-01 00:00:00')
但它并不总是我期望的“魔术”,例如,以下是非法的:
In [41]: pd.Timestamp('202003') # expecting 2020-03-01
ValueError: could not convert string to Timestamp
In [42]: pd.Timestamp('2020H2') # expecting 2020-07-01, i.e. 2020 second half (start)
ValueError: could not convert string to Timestamp
我试图找到完整的支持格式列表,但看来文档丢失了(或者我缺少某些内容)。谁能帮忙?谢谢!
I find that pandas.Timestamp is extremely powerful and flexible parsing tool that accepts a wide range of timestamp/datetime formats. E.g.
In [38]: pd.Timestamp('2020')
Out[38]: Timestamp('2020-01-01 00:00:00')
In [39]: pd.Timestamp('2020-02')
Out[39]: Timestamp('2020-02-01 00:00:00')
In [40]: pd.Timestamp('2020Q1')
Out[40]: Timestamp('2020-01-01 00:00:00')
But it doesn't always do the "magic" I was expecting, e.g. the followings are illegal:
In [41]: pd.Timestamp('202003') # expecting 2020-03-01
ValueError: could not convert string to Timestamp
In [42]: pd.Timestamp('2020H2') # expecting 2020-07-01, i.e. 2020 second half (start)
ValueError: could not convert string to Timestamp
I tried to find a complete list of supported formats but it seems that the document is missing (or I'm missing something). Can anyone help? Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果研究年度
和日期,请使用四分之一
Use quarters if looking into annual periods
and for dates
pd.timestamp()
是Python的DateTime等效的熊猫,在大多数情况下可以与之互换。 DateTime库接受ISO 8601日期格式。在Python ISO 8601中,日期以
yyyy-mm-ddthh:mm:ss.mmmmmm
格式表示。例如,2022年5月18日,表示为2022-05-18T11:40:22.519222
。yyyy
:四位数格式的一年mm
:1-12 DD的月份:从1到31到31t
:这是分隔符字符那是在日期和时间字段。这是一个可选参数,默认
“ t”的价值。
HH
:对于分钟的值mm
:对于分钟的指定值ss
:对于秒的指定值mmmmmmm :对于指定的微秒
直接从pandas文档() 在这里 ):
示例
使用主要呼叫惯例:
这将转换一个类似日期的字符串的字符串,
的浮点
几秒钟的单位转换代表Unix epoch
以 :
pd.timestamp()
is the pandas equivalent of python’s Datetime and is interchangeable with it in most cases. Datetime library accepts ISO 8601 date formats.In Python ISO 8601 date is represented in
YYYY-MM-DDTHH:MM:SS.mmmmmm
format. For example, May 18, 2022, is represented as2022-05-18T11:40:22.519222
.YYYY
: Year in four-digit formatMM
: Months from 1-12 DD: Days from 1 to 31T
: It is the separator character that is to be printed between thedate and time fields. It is an optional parameter having a default
value of “T”.
HH
: For the value of minutesMM
: For the specified value of minutesSS
: For the specified value of secondsmmmmmm
: For the specified microsecondsDirectly from the Pandas documentation (here):
Examples
Using the primary calling convention:
This converts a datetime-like string
This converts a float representing a Unix epoch in units of seconds
This converts an int representing a Unix-epoch in units of seconds and for a particular timezone
Using the other two forms that mimic the API for datetime.datetime: