英文:
Pandas: Different behavior of merge in pandas version 1.1.5 and 1.2.0
问题
I'll provide a translation of the code and description:
mapping = pd.merge(
df_1, df_2, how="left", on=["DLM"]
)
上面的代码执行了pandas版本1.1.5的操作,但该代码不适用于1.2.0或更高版本的pandas,它不会引发任何错误,但即使有连接的数据也无法正确连接。
示例:
df_1
A | DLM |
---|---|
1 | 2 |
3 | 4 |
df_2
DLM | B |
---|---|
2 | 3 |
pandas 1.1.5的结果
A | DLM | B |
---|---|---|
1 | 2 | 3 |
3 | 4 | NaN |
pandas 1.2.0的结果
A | DLM | B |
---|---|---|
1 | 2 | NaN |
3 | 4 | NaN |
附注:这不是我的确切数据,我不能发布我正在使用的数据。
英文:
mapping = pd.merge(
df_1, df_2, how="left", on=["DLM"]
)
The above code executes and does the job done for pandas version 1.1.5 but the code doesn't work for pandas 1.2.0 or above, it doesn't throw any error but even though there will be a joining partner it doesn't join properly
Example
df_1
A | DLM |
---|---|
1 | 2 |
3 | 4 |
df_2
DLM | B |
---|---|
2 | 3 |
Result of pandas 1.1.5
A | DLM | B |
---|---|---|
1 | 2 | 3 |
3 | 4 | NaN |
Result of pandas 1.2.0
A | DLM | B |
---|---|---|
1 | 2 | NaN |
3 | 4 | NaN |
PS : This is not my data exactly and I can't post the data which I am using.
答案1
得分: 1
I will translate the provided content:
The release notes talk about a bug resolved in version 1.2.0.:
Bug in DataFrame.merge() and pandas.merge() returning inconsistent ordering in result for how=right and how=left (GH35382)
I assume this is what causes the function to work differently in the two versions.
英文:
The release notes talk about a bug resolved in version 1.2.0.:
> Bug in DataFrame.merge() and pandas.merge() returning inconsistent ordering in result for how=right and how=left (GH35382)
I assume this is what causes the function to work differently in the two versions.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论