title: Merging two dataframes based on common values using pandas python?
body: <p>This is my first question on stackoverflow so please bear with me.<br />
  I'm new to pandas, I need to merge two dataframes based on values in columns:</p>
  <p>df1:</p>
  <pre><code>   Col1  Col2
  0   A    10
  1   B    12
  2   C    22
  3   D    22
  4   E    22
  5   F    11
  6   G    55
  7   H    60
  </code></pre>
  <p>df2:</p>
  <pre><code>   Col3 Col4
  0   J    11
  1   K    22
  2   L    22
  3   M    60
  4   N    80
  5   O    45
  6   P    12
  7   Q    65
  </code></pre>
  <p>The resulting dataframe should be like:</p>
  <pre><code>  Col1  Col2    Col3    Col4
  0   B    12       P      12
  1   C    22       K      22
  2   D    22       L      22
  3   H    60       M      60
  </code></pre>
  <p>It should compare Col2 and Col4 and only keep common rows and merge two data frames into one.
  I tried following code but result is not what I desire.</p>
  <pre><code>both_DFS=df1.merge(df2,left_on='Col2',right_on='Col4')
  </code></pre>
  <p>For this result is:</p>
  <pre><code>  Col1  Col2    Col3    Col4
  0   B    12       P      12
  1   C    22       K      22
  2   C    22       L      22
  3   D    22       K      22
  4   D    22       L      22
  5   E    22       K      22
  6   E    22       L      22
  7   H    60       M      60
   
  </code></pre>