我有一个包含时间戳数据的 pandas 列
I have a pandas column of Timestamp data
In [27]: train["Original_Quote_Date"][6]
Out[27]: Timestamp('2013-12-25 00:00:00')
如何检查这些对象与 datetime.date
类型的对象的等价性
How can check equivalence of these objects to datetime.date
objects of the type
datetime.date(2013, 12, 25)
使用.date
方法:
In [11]: t = pd.Timestamp('2013-12-25 00:00:00')
In [12]: t.date()
Out[12]: datetime.date(2013, 12, 25)
In [13]: t.date() == datetime.date(2013, 12, 25)
Out[13]: True
<小时>
要与 DatetimeIndex(即时间戳数组)进行比较,您需要反过来:
To compare against a DatetimeIndex (i.e. an array of Timestamps), you'll want to do it the other way around:
In [21]: pd.Timestamp(datetime.date(2013, 12, 25))
Out[21]: Timestamp('2013-12-25 00:00:00')
In [22]: ts = pd.DatetimeIndex([t])
In [23]: ts == pd.Timestamp(datetime.date(2013, 12, 25))
Out[23]: array([ True], dtype=bool)
这篇关于 pandas :将时间戳转换为 datetime.date的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!