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

简介: You are trying to merge on object and int64 columns. If you wish to proceed you should use pd.conca

前言

是在用pandas合并Dataframe的时候遇到的这个问题,

pd.merge(df_borough, df_price , how=‘left’, on=‘other_id’).fillna(value=0)


问题原因

问题的原因是两个Dataframe根据合并的字段other_id的类型不一样导致了这个问题, 说来也玄学…跑了很多其他都没事, 一模一样塞入的类型


解决

使用 df_borough.dtypes 查看Dataframe的类型, 然后用 .apply(int) 方法转成同样的类型就可以了


目录
相关文章
Python之pandas:数据类型变换之object、category、bool、int32、int64、float64以及数据类型标准化之详细攻略
Python之pandas:数据类型变换之object、category、bool、int32、int64、float64以及数据类型标准化之详细攻略
Python之pandas:数据类型变换之object、category、bool、int32、int64、float64以及数据类型标准化之详细攻略
|
3月前
|
开发者 Python
【Python】已解决:TypeError: a bytes-like object is required, not ‘int’
【Python】已解决:TypeError: a bytes-like object is required, not ‘int’
81 0
|
Python
Python POST data should be bytes, an iterable of bytes, or a file object. It ...
Python POST data should be bytes, an iterable of bytes, or a file object. It ...
107 0
成功解决AttributeError: ‘Series‘ object has no attribute ‘columns‘
成功解决AttributeError: ‘Series‘ object has no attribute ‘columns‘
Pandas pd.merge() 报错:ValueError: You are trying to merge on int64 and object columns.
Pandas pd.merge() 报错:ValueError: You are trying to merge on int64 and object columns.
Pandas pd.merge() 报错:ValueError: You are trying to merge on int64 and object columns.
|
PHP
【laravel】模型一对一Trying to get property 'price' of non-object
【laravel】模型一对一Trying to get property 'price' of non-object
138 0
【laravel】模型一对一Trying to get property 'price' of non-object