Examples

In [1]:
import numpy as np
import pandas as pd
In [2]:
df1 = pd.DataFrame({'lkey': ['faa', 'baa', 'bzz', 'faa'],
                    'value': [2, 3, 5, 7]})
df2 = pd.DataFrame({'rkey': ['faa', 'baa', 'bzz', 'faa'],
                    'value': [7, 8, 9, 10]})
df1
Out[2]:
lkey value
0 faa 2
1 baa 3
2 bzz 5
3 faa 7

Pandas: DataFrame - Merge.

In [3]:
df2
Out[3]:
rkey value
0 faa 7
1 baa 8
2 bzz 9
3 faa 10
In [4]:
df1.merge(df2, left_on='lkey', right_on='rkey')
Out[4]:
lkey value_x rkey value_y
0 faa 2 faa 7
1 faa 2 faa 10
2 faa 7 faa 7
3 faa 7 faa 10
4 baa 3 baa 8
5 bzz 5 bzz 9

Pandas: DataFrame - Merge.

Merge DataFrames df1 and df2 with specified left and right suffixes appended
to any overlapping columns.

In [5]:
df1.merge(df2, left_on='lkey', right_on='rkey',
          suffixes=('_left', '_right'))
Out[5]:
lkey value_left rkey value_right
0 faa 2 faa 7
1 faa 2 faa 10
2 faa 7 faa 7
3 faa 7 faa 10
4 baa 3 baa 8
5 bzz 5 bzz 9