数据框中的某些值未从excel fi中正确提取

2024-10-08 20:16:36 发布

您现在位置:Python中文网/ 问答频道 /正文

我需要比较到的日期,一个是来自数据帧的日期,另一个只是我使用deltatime到两天前的日期。像这样:
elif np.greater(ddate,datetime.now() - timedelta(2)):

问题是,这段代码一直工作得很好,直到今天,当我尝试比较这些日期时,我得到了以下错误: TypeError: '>' not supported between instances of 'int' and 'datetime.datetime'

我正在使用此代码从excel中提取日期:

ddate = df_earning_calander.loc[df_earning_calander.index == stock_symbol, 'date'][stock_symbol]
为了找到问题,我打印了ddate结果,我找到了这个。
(此代码位于循环中,因此第一行是正确的,而第二行不是)

2019-08-08 00:00:00
KHC   2019-08-08

当其中一个值还包含其旁边的列时,错误将跳转。。。这很奇怪,因为数据帧是这样构建的:
print(ddate,bmo_amc,stock_symbol,company_name)
2019-08-08 00:00:00 Before The Open KOP Koppers Holdings

我认为这可能是问题所在,尽管我不确定
这就是Excel的构建方式:
enter image description here

你知道怎么解决这个问题吗


Tags: 数据代码dfdatetime错误stocknpsymbol

热门问题