代码:

order.rename({'info_id':'order_id'},inplace=True)
order_detail1 = detail1.join(order,on='order_id',rsuffix='1')
print('订单详情表和订单信息表join合并后的形状为:',order_detail1.shape)

出现这样错误

python中 join合并主键 出现的bugYou are trying to merge on object and int64 columns_解决方法

解决方法发现发现order[‘order_id’]和detail1[‘order_id’]的类型是object,将其转换成int类型就可以了

python中 join合并主键 出现的bugYou are trying to merge on object and int64 columns_解决方法_02

python中 join合并主键 出现的bugYou are trying to merge on object and int64 columns_解决方法_03


修改:

order.rename(columns={'info_id':'order_id'},inplace=True)
detail1['order_id'] = detail1['order_id'].astype(int)
order['order_id'] = order['order_id'].astype(int)
order_detail1 = detail1.join(order,on='order_id',rsuffix='1')
print('订单详情表和订单信息表join合并后的形状为:',order_detail1.shape)

成功了

python中 join合并主键 出现的bugYou are trying to merge on object and int64 columns_解决方法_04


总结:

python中 join合并主键 出现的bugYou are trying to merge on object and int64 columns_解决方法_05