【问题标题】:Pandas join on these two dataframes causes value error, but different errors for different versions, and why?熊猫加入这两个数据帧会导致值错误,但不同版本的错误不同,为什么?
【发布时间】:2020-04-24 12:43:57
【问题描述】:

可能重复pandas - Merging on string columns not working (bug?)

尝试合并以下两个数据帧时,我收到了有趣的消息。有谁知道发生了什么?删除 E 可以修复错误。

newvi = pd.DataFrame({'a':['E1000305', 'E1000505', 'E1001071', 'E99836', 'E1003822']})
newsm = pd.DataFrame({'a':['E1000305', 'E1000305', 'E1000305', 'E1000305', 'E1000305']})

newvi.a
#0    E1000305
#1    E1000505
#2    E1001071
#3      E99836
#4    E1003822
#Name: a, dtype: object
newsm.a
#0    E1000305
#1    E1000305
#2    E1000305
#3    E1000305
#4    E1000305
#Name: a, dtype: object

newvi.join(newsm, on='a')

#my computer
#ValueError: columns overlap but no suffix specified: Index([u'a'], dtype='object')

>>> pd.__version__
u'0.18.1'

#server

#ValueError: You are trying to merge on object and int64 columns. If you wish to proceed you should use pd.concat

>>> pd.__version__
'0.24.2'

【问题讨论】:

  • 您希望连接的数据框是什么样的?

标签: python pandas


【解决方案1】:

newvi.join(newsm.set_index('a'), on='a')

将索引设置为“a”似乎可以解决您的错误,结果是否符合您的预期?

【讨论】:

猜你喜欢
  • 2023-04-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-05-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多