小编Bir*_*Bud的帖子

Pandas Left Join 会产生比 Left Dataframe 更多的行

我在生成的左连接中的行数比左数据框中的行数多。

# Importing Pandas and changing it's call to pd
import numpy as np
import pandas as pd

SalesDF = pd.read_csv(r"C:\Users\USER\Documents\Reports\SalesForAnalysis.csv")
print("This is the Sales shape")
print(SalesDF.shape)


CustInfoDF = pd.read_csv(r"C:\Users\USER\Documents\Cust.csv")

# This reassigns the df so that the rows with a NaN in the Account Number it  doesn't appear
CustInfoDF = CustInfoDF[CustInfoDF['Account Number'].notna()]


# Merges the two dataframes on SalesDF with "Cust Number" as the key
MergeDF = pd.merge(SalesDF, CustInfoDF, how="left", left_on="Cust Number", right_on="Account Number")

print("This is the Merge Shape …
Run Code Online (Sandbox Code Playgroud)

python merge left-join dataframe pandas

4
推荐指数
1
解决办法
2911
查看次数

标签 统计

dataframe ×1

left-join ×1

merge ×1

pandas ×1

python ×1