首页 > 解决方案 > ValueError:您正在尝试合并 object 和 int64 列。如果你想继续,你应该使用 pd.concat

问题描述

您好我正在尝试执行模糊匹配器代码,但出现以下错误:

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

即使我要匹配的列的类型相同,也会发生这种情况,有问题的变量位于P009_01, P009_2, P009_03左侧和apellido1, apellido2, names右侧数据框上。

df1.dtypes

P001                 int64
P002                 int64
P003                 int64
P017                object
P020_01            float64
WP109                int64
WP114                int64
WP115                int64
P009_01             object
P009_02             object
P009_03             object
tenure_security    float64
inv2                object
P086_01             object
inv7                object
inv11               object
P121               float64
c_ubigeo             int64
dtype: object

另一个:

df2.dtypes

COD_PREDIO       object
AREA_HA         float64
DEPARTAMENTO     object
PREDIO           object
NUM_PREDIO        int64
ID_DIST           int64
ID_PROV           int64
P001              int64
P009_01          object
P009_02          object
P009_03          object
P002              int64
P003              int64
p_ubigeo          int64
ubigeo            int64
apellido1        object
apellido2        object
nombres          object
PETT_0            int64
dtype: object

需要匹配的变量来自同一类型,所以我看不出问题出在哪里,有人能发现吗?这是代码:

matched_results = fuzzymatcher.fuzzy_left_join(df1,
                                           df2,
                                           left_on,
                                           right_on,
                                           left_id_col = 'P003',
                                           right_id_col = 'ID_DIST')

我错过了什么吗?提前致谢!

标签: objectjoinmergevalueerrorint64

解决方案


推荐阅读