Pandas: Different behavior of merge in pandas version 1.1.5 and 1.2.0

huangapple go评论60阅读模式
英文:

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.

huangapple
  • 本文由 发表于 2023年4月6日 21:25:02
  • 转载请务必保留本文链接:https://go.coder-hub.com/75950073.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定