0

我正在尝试连接从 SQL 查询创建的两个 DataFrame(称为 firstData 和 lastData)。但是,当我尝试连接它们时,我收到一条错误消息TypeError: can't compare datetime.datetime to int。从这条消息来看,我认为问题在于与 AUTHORIZED 字段的连接。具有数据框外观的虚拟数据如下。关于如何解决这个问题的任何想法?

print firstData
  ORDER_ID    EMAIL             IP       AUTHORIZED  
0   1234567   dummy@dummy.net   x.x.x.x  2008-11-15 19:16:07   
1   8911234   dummy@dummy.com   x.x.x.x  2008-11-15 17:59:55   
2   4567833   dummy@dummy.com   x.x.x.x  2008-11-15 17:50:20   

     HOUR  DAY_OF_WEEK SHIPMENT_TYPE  ZIPS_MATCH     MERCH_SUBCAT     
0    19    7           Standard       1              Her Accessory      
1    17    7           Standard       1              Her Accessory      
2    17    7           Standard       1              Kid toy/clothes

print lastData   
  ORDER_ID  EMAIL              IP     AUTHORIZED 
3   1234567 dummy@dummy.net  x.x.x.x  2008-11-15 17:43:13 
4   8901234 dummy@dummy.com  x.x.x.x  2008-11-15 13:18:01    
5   4567890 dummy@dummy.com  x.x.x.x  2008-11-15 09:29:10   

   HOUR DAY_OF_WEEK  SHIPMENT_TYPE      ZIPS_MATCH    MERCH_SUBCAT
3  17    7           Standard           1             Bag   
4  13    7           Standard           1             Paperweight/boxes     
5  09    7           Standard           0             Candle   


concat(firstData, lastData)
   TypeError: can't compare datetime.datetime to int
4

1 回答 1

2

您需要将or对象的listdicttuple或生成器传递给. 您现在所做的将抛出 a因为正在作为参数传递(并且有许多行,例如,这将触发 a )。像这样做:DataFrameSeriesconcatTypeErrorlastDataaxisaxis == 0TypeError

In [31]: a
Out[31]:
   0        1                2        3           4         5
0  0  1234567  dummy@dummy.net  x.x.x.x  2008-11-15  19:16:07
1  1  8911234  dummy@dummy.com  x.x.x.x  2008-11-15  17:59:55
2  2  4567833  dummy@dummy.com  x.x.x.x  2008-11-15  17:50:20

In [32]: b
Out[32]:
   0        1                2        3           4         5
0  3  1234567  dummy@dummy.net  x.x.x.x  2008-11-15  17:43:13
1  4  8901234  dummy@dummy.com  x.x.x.x  2008-11-15  13:18:01
2  5  4567890  dummy@dummy.com  x.x.x.x  2008-11-15  09:29:10

In [33]: concat([a, b])
Out[33]:
   0        1                2        3           4         5
0  0  1234567  dummy@dummy.net  x.x.x.x  2008-11-15  19:16:07
1  1  8911234  dummy@dummy.com  x.x.x.x  2008-11-15  17:59:55
2  2  4567833  dummy@dummy.com  x.x.x.x  2008-11-15  17:50:20
0  3  1234567  dummy@dummy.net  x.x.x.x  2008-11-15  17:43:13
1  4  8901234  dummy@dummy.com  x.x.x.x  2008-11-15  13:18:01
2  5  4567890  dummy@dummy.com  x.x.x.x  2008-11-15  09:29:10

In [34]: concat([a, b], axis=1)
Out[34]:
   0        1                2        3           4         5  0        1  \
0  0  1234567  dummy@dummy.net  x.x.x.x  2008-11-15  19:16:07  3  1234567
1  1  8911234  dummy@dummy.com  x.x.x.x  2008-11-15  17:59:55  4  8901234
2  2  4567833  dummy@dummy.com  x.x.x.x  2008-11-15  17:50:20  5  4567890

                 2        3           4         5
0  dummy@dummy.net  x.x.x.x  2008-11-15  17:43:13
1  dummy@dummy.com  x.x.x.x  2008-11-15  13:18:01
2  dummy@dummy.com  x.x.x.x  2008-11-15  09:29:10

这现在引发了一个AssertionError, since commit 36142334(在 v0.12.0 版本中),所以你不会再收到这个神秘的错误了。

于 2013-10-07T16:05:27.663 回答