I have 2 dataframes which i want to merge using 2 columns as Keys and create another merged dataframe. Here, Column1 is String and Columns2 is float datatype. I want to put tolerance of .01 on column2 such that (John, 1.12) from dataframe1 and (John, 1.13) from dataframe2 should come in same row. How can i achieve that ?
For example : 2 Dataframes :
df1 = pd.DataFrame({"Name":["John","Millon"], "MarketVal":[1.12,2.11], "Left_Product":["Sugar","Salt"]})
df2 = pd.DataFrame({"Name":["John","Rex"], "MarketVal":[1.13,3.11], "right_Product":["Sugar","Salt"]})
if I do :
dfMerge = pd.merge(df1,df2,on=["Name","MarketVal"], how= "outer")
then this will create 2 separate rows for "John" since MarketVal is different in both dataframes. But I want to keep tolerance of .01 on this so that they come at same row.
Actual :->
Name MarketVal Left_Product right_Product
0 John 1.12 Sugar NaN
1 Millon 2.11 Salt NaN
2 John 1.13 NaN Sugar
3 Rex 3.11 NaN Salt
Expected :->
Name MarketVal Left_Product right_Product
0 John 1.12 Sugar Sugar
1 Millon 2.11 Salt NaN
2 Rex 3.11 NaN Salt