SQL-like merging/joining of DataFrame objects

The merge function is used to join two DataFrame objects similar to those used in SQL database queries. It results in a merged DataFrame. DataFrame objects are analogous to SQL tables. The following command explains this:

    merge(left, right, how='inner', on=None, left_on=None,
          right_on=None, left_index=False, right_index=False, 
          sort=True, suffixes=('_x', '_y'), copy=True)

The following is a summary of the merge function:

  • The left argument: This is the first DataFrame object.
  • The right argument: This is the second DataFrame object.
  • The how argument: This is the type of join and can be inner, outer, left, or right. The default is inner.
  • The on argument: This shows the names of columns to join ...

Get Mastering pandas - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.