Q:

Getting a merged dataframe from two dataframe

I have two dataframe:
Source dataframe
index   A   x       y
1       1   100     100
2       1   100     400
3       1   100     700
4       1   300     200
5       2   50      200
6       2   100     200
7       2   800     400
8       2   1200    800

Destination dataframe
index   A   x       y
1       1   105     100
2       1   110     410
3       1   110     780
4       2   1000    90

For each row in source dataframe I need to find values nearest to it based on values in the destination dataframe grouped by 'A' column. The resultant dataframe should be as below(Just a sample taking only one row from source(index 1) and corresponding nearest ones from destination in that group(A == 1))
A   x_1     y_1     x_2     y_2     nearness(approx.)
1   100     100     105     100     95
1   100     100     110     410     50
1   100     100     110     780     20

NOTE: The nearness column is just a mere representation and will be a calculation function in the future based on x and y. What I need is row wise merging between the two dataframe.
This might be arbitrary, but can someone explain how merge works?

A:

pd.merge(source_df, dest_df, on='A')
Basically, it will go through every item of the left dataframe, look for its key in the right dataframe, and create an entry in the merged datagrame (it creates an entry for each time the key is found in the right dataframe, but you can change this behaviour with the validate keyword)
https://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.merge.html for more infos!!!

