pandas 如何创建熊猫时间戳对象?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 
原文地址: http://stackoverflow.com/questions/21599633/
Warning: these are provided under cc-by-sa 4.0 license.  You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to create a pandas Timestamp object?
提问by Mannaggia
It might sound like a trivial question, but I was not able to find proper documentation on this including help(pd.Timestamp) which does not provide a clear constructor.
这听起来像是一个微不足道的问题,但我无法找到有关此问题的适当文档,包括 help(pd.Timestamp) ,它没有提供明确的构造函数。
I want to create the last time stamp of eg day 2012-12-13, so hour is 23, minute is 59, seconds is 59, nanosecond is 999999999
我想创建例如 2012-12-13 的最后一个时间戳,所以小时是 23,分钟是 59,秒是 59,纳秒是 999999999
alternatively, if I have microsecond precision the last timestamp of a day would be as before except microsecond is 999999
或者,如果我有微秒精度,一天的最后一个时间戳将与以前一样,除了微秒是 999999
I need this to filter out all timestamps until a given (end of) day by indexing the original series by something like df.ix[:last_timestamp]
我需要通过使用 df.ix[:last_timestamp] 之类的东西索引原始系列来过滤掉所有时间戳,直到给定(结束)一天
Thx
谢谢
采纳答案by Jeff
In [1]: Timestamp('20131213 11:59:59.999999999')
Out[1]: Timestamp('2013-12-13 11:59:59.999999', tz=None)
You can also do
你也可以这样做
In [3]: pd.Timestamp('20141213')-pd.Timedelta('1ns')
Out[3]: Timestamp('2014-12-12 23:59:59.999999999')
Sounds like you actually want to use partial string slicing, see here
听起来您实际上想使用部分字符串切片,请参见此处
In [19]: s = Series(1,pd.date_range('20131212',freq='H',periods=25))
In [20]: s
Out[20]: 
2013-12-12 00:00:00    1
2013-12-12 01:00:00    1
2013-12-12 02:00:00    1
                      ..
2013-12-12 22:00:00    1
2013-12-12 23:00:00    1
2013-12-13 00:00:00    1
Freq: H, dtype: int64
In [21]: s['2013':'20131212']
Out[21]: 
2013-12-12 00:00:00    1
2013-12-12 01:00:00    1
2013-12-12 02:00:00    1
                      ..
2013-12-12 21:00:00    1
2013-12-12 22:00:00    1
2013-12-12 23:00:00    1
Freq: H, dtype: int64

