我在生成的左连接中的行数比左数据框中的行数多。
# 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)