Conditional joining Pandas dataframes
This is the textbook example of an inner join. The most canonical way to have your id columns being used for the matching, set them as an index first (here using inplace operations to save on extra variable names; depending on your use, you might prefer new copies instead):

dat1.set_index('id', inplace=True)
dat2.set_index('id', inplace=True)


Then, the whole operation becomes this simple join on index:

&gt;&gt;&gt; overall_data = dat1.join(dat2, how='inner')
&gt;&gt;&gt; overall_data

    dat1  dat2
id
2     56    19
3     57    19
4     45    20


If you do not want to modify the original DataFrames, you can use utility function merge instead, which performs the same operation, but needs the common column name specified explicitely:

&gt;&gt;&gt;  pd.merge(dat1, dat2, how='inner', on='id')

   id  dat1  dat2
0   2    56    19
1   3    57    19
2   4    45    20