0
我想搜索一个特定的日期是否存在于一个熊猫数据框中,但是,我发现了一些特殊的日期行为,如下所示。我对Python和熊猫是新手 - 所以任何帮助表示赞赏。在熊猫数据框内搜索日期
样品数据框:
>>> hd.dtypes
Date datetime64[ns]
NAV float64
dtype: object
>>> hd.head()
Date NAV
2004-04-01 41.106
2004-04-02 41.439
2004-04-05 41.727
2004-04-06 41.667
2004-04-07 41.770
基本上我试图找到一个特定日期“NEXT_DAY”存在于hd['Date']
作为below.The代码总是返回not present
这令我感到困惑。我试图将next_day
设置为hd
数据帧中的第一个日期,该数据帧应始终满足 - 但它仍显示not present
。 然而代码工作当我使用非datetime列:
>>> next_day = hd['Date'][0]
>>> if (next_day not in hd['Date']):
print 'not present'
else:
print 'present'
>>> not present
>>>if (41.106 not in hd['NAV']):
print 'not present'
else:
print 'present'
>>> present
这是否与日期时间转换?