简体   繁体   English

Python Pandas 用内连接合并 2 个表:

[英]Python Pandas merging 2 tables with inner join:

Hi I am merging two tables with an inner join using pandas but I am getting a weird output.嗨,我正在使用 pandas 合并两个带有内部连接的表,但我得到了一个奇怪的 output。 Below I am pasting the two tables:下面我粘贴两个表: 在此处输入图像描述

在此处输入图像描述

I want to inner join the tables so it only shows the zipcodes in the df2 table so I use this line:我想内部连接表,所以它只显示 df2 表中的邮政编码,所以我使用这一行:
result = pd.merge(ppy, df2, how="inner", on=["zipcode"])结果 = pd.merge(ppy, df2, how="inner", on=["zipcode"])

But now I am getting two records for each zipcode但现在我得到了每个邮政编码的两条记录

在此处输入图像描述

Anyone have any idea on how to fix this or what might be causing this issue?任何人都知道如何解决此问题或可能导致此问题的原因?

The data types of zipcode variables in datasets can be different.数据集中邮政编码变量的数据类型可以不同。 Check it with the dtype () method.使用 dtype () 方法检查它。 If the data types are different, you can combine them and combine them.如果数据类型不同,可以合并,合并。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM