Data merging in python(Data Minig)

data_mining
python

#1

Hey All,
Can anyone help me to know why data value(No. of rows) is less after merging, and how i can get the all data of GEN_3 with merge one column from P_List.
Note: In both the file one "Key"column is there.

Input:
GEN_3=  pd.read_csv("~/Dec.csv",encoding="iso-8859-1")
P_List = pd.read_csv("~/P_List.csv",encoding="iso-8859-1")
print(GEN_3.shape)
GEN_Mer = pd.merge(GEN_3,P_List)
print(GEN_Mer.shape)

Output:
(442155, 8)
(377761, 9)

Thank You


#2

You need to specify the how do you want to merge the two dataframes. Default value of how is ‘inner’ so only, the same values will be merged. I think what you want is append. Append the both the dataframes and then you can get your desired result.


#3

Apply left merge on key column.It will work.

Df = GEN_3.merge(P_List,how=“left”,on=“keycolumn”)

Link for reference: https://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.merge.html