python
data_error
ai_generated
true
ValueError:正在尝试在 int64 和 object 列上进行合并。如果希望继续,请使用 pd.concat
ValueError: You are trying to merge on int64 and object columns. If you wish to proceed you should use pd.concat
ID: python/pandas-merge-type-mismatch
80%修复率
90%置信度
0证据数
2024-09-25首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 3.x | active | — | — | — |
根因分析
连接键 dtype 不匹配(整数 vs 字符串),无法进行相等匹配。
English
Join keys have mismatched dtypes (int vs string), preventing equality matches.
解决方案
-
95% 成功率
df1['key'] = df1['key'].astype(str); df2['key'] = df2['key'].astype(str)
-
85% 成功率
pd.merge(df1, df2, left_on=df1.key.astype(int), right_on='key')
无效尝试
常见但无效的做法:
-
80% 失败
Produces cartesian/incorrect rows
-
85% 失败
Same dtype error