I run Python 3.6 on Windows 10.
My code is the following:
data1
Loan_ID Gender
1 LP001003 Male
2 LP001005 Male
3 LP001006 Male
4 LP001008 Male
5 LP001011 Male
data2
Loan_ID2 LoanAmount
1 LP001003 128.0
2 LP001005 66.0
3 LP001006 120.0
4 LP001008 141.0
5 LP001011 267.0
data_merged = data1.merge(right= data2, how='inner',left_on='Loan_ID', right_on = 'Loan_ID2',right_index=True, sort=False)
data_merged.shape
(0, 4)
You do not need right_index
within merge
df1.merge(df2,left_on='Loan_ID',right_on='Loan_ID2')
Out[54]:
Loan_ID Gender Loan_ID2 LoanAmount
0 LP001003 Male LP001003 128.0
1 LP001005 Male LP001005 66.0
2 LP001006 Male LP001006 120.0
3 LP001008 Male LP001008 141.0
4 LP001011 Male LP001011 267.0
Try renaming your column in data2
, this'll simplify your merge code a bit.
data1.merge(data2.rename(columns={'Loan_ID2' : 'Loan_ID'}), on='Loan_ID')
Loan_ID Gender LoanAmount
0 LP001003 Male 128.0
1 LP001005 Male 66.0
2 LP001006 Male 120.0
3 LP001008 Male 141.0
4 LP001011 Male 267.0
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With