w3resource

Pandas DataFrame: join() function

DataFrame - join() function

The join() function is used to join columns of another DataFrame.

Join columns with other DataFrame either on index or on a key column. Efficiently join multiple DataFrame objects by index at once by passing a list.

Syntax:

DataFrame.join(self, other, on=None, how='left', lsuffix='', rsuffix='', sort=False)

Parameters:

Name Description Type/Default Value Required / Optional
other Index should be similar to one of the columns in this one. If a Series is passed, its name attribute must be set, and that will be used as the column name in the resulting joined DataFrame. DataFrame, Series, or list of DataFrame Required
on  Column or index level name(s) in the caller to join on the index in other, otherwise joins index-on-index. If multiple values given, the other DataFrame must have a MultiIndex. Can pass an array as the join key if it is not already contained in the calling DataFrame. Like an Excel VLOOKUP operation. str, list of str, or array-like Optional
how  How to handle the operation of the two objects.
  • left: use calling frame's index (or column if on is specified)
  • right: use other's index.
  • outer: form union of calling frame's index (or column if on is specified) with other's index, and sort it. lexicographically.
  • inner: form intersection of calling frame's index (or column if on is specified) with other's index, preserving the order of the calling's one.
{'left', 'right', 'outer', 'inner'}
Default Value: 'left'
Required
lsuffix   Suffix to use from right frame's overlapping columns. str
Default Value: ''
Required
rsuffix  Suffix to use from right frame's overlapping columns. str
Default Value: ''
Required
sort  Order result DataFrame lexicographically by the join key. If False, the order of the join key depends on the join type (how keyword). bool
Default Value: False
Required

Returns: DataFrame
A dataframe containing columns from both the caller and other.

Example:


Download the Pandas DataFrame Notebooks from here.

Previous: DataFrame - assign() function
Next: DataFrame - merge() function



Follow us on Facebook and Twitter for latest update.