I have got two dataframes:
df1 = pd.DataFrame(data =
{'Invoice' : [1, 2, 3, 4, 5], 'Value' : [10, 25, 40, 10, 15]})
df2 = pd.DataFrame(data =
{'Invoice' : [2, 3, 5, 2], 'Value' : [25, 11, 15,25], 'TestData':["A",'B','C','D']})
I've already merged them and get df3:
df3=pd.merge(df1,df2, left_on=["Invoice","Value"], right_on=["Invoice","Value"])
Df3 output:
Invoice Value TestData
0 2 25 A
1 2 25 D
2 5 15 C
My question is how to get merged dataframe with "one-to-one" (I mean - when invoice number 2 occurs only once (or generally less) in one of two dataframes, then don't create another row with invoice number 2 in merged dataframe). I'd like to get something like this:
Invoice Value TestData
0 2 25 A
1 5 15 C
or this:
Invoice Value TestData
0 2 25 D
1 5 15 C
I tried only left and right merging, but this doesn't work - there are always two rows with invoice number 2.
Thank you,
Jarek