# dask.dataframe.DataFrame.join

#### DataFrame.join(other, on=None, how='left', lsuffix='', rsuffix='', shuffle_method=None, npartitions=None)

Join columns of another DataFrame.

This docstring was copied from pandas.DataFrame.join.

Some inconsistencies with the Dask version may exist.

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.

* **Parameters:**
  **other**
  : Index should be similar to one of the columns in the caller. 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.

  **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.

  **how**
  : default ‘left’
    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.
    * cross: creates the cartesian product from both frames, preserves the order
      of the left keys.
    * left_anti: use set difference of calling frame’s index and other’s
      index.
    * right_anti: use set difference of other’s index and calling frame’s
      index.

  **lsuffix**
  : Suffix to use from left frame’s overlapping columns.
    <br/>
    #### Deprecated
    Deprecated since version 3.1.0: Use `suffixes` instead.

  **rsuffix**
  : Suffix to use from right frame’s overlapping columns.
    <br/>
    #### Deprecated
    Deprecated since version 3.1.0: Use `suffixes` instead.

  **sort**
  : Order result DataFrame lexicographically by the join key. If False,
    the order of the join key depends on the join type (how keyword).

  **validate**
  : If specified, checks if join is of specified type.
    * “one_to_one” or “1:1”: check if join keys are unique in both left
      and right datasets.
    * “one_to_many” or “1:m”: check if join keys are unique in left dataset.
    * “many_to_one” or “m:1”: check if join keys are unique in right dataset.
    * “many_to_many” or “m:m”: allowed, but does not result in checks.

  **suffixes**
  : A length-2 sequence where each element is optionally a string
    indicating the suffix to add to overlapping column names in
    the caller and `other` respectively. Pass a value of `None`
    instead of a string to indicate that the column name from
    the caller or `other` should be left as-is, with no suffix.
    At least one of the values must not be None.
* **Returns:**
  DataFrame
  : A dataframe containing columns from both the caller and other.

#### SEE ALSO
[`DataFrame.merge`](dask.dataframe.DataFrame.merge.html.md#dask.dataframe.DataFrame.merge)
: For column(s)-on-column(s) operations.

### Notes

Parameters on and suffixes are not supported when
passing a list of DataFrame objects.

### Examples

```pycon
>>> df = pd.DataFrame(
...     {
...         "key": ["K0", "K1", "K2", "K3", "K4", "K5"],
...         "A": ["A0", "A1", "A2", "A3", "A4", "A5"],
...     }
... )
```

```pycon
>>> df
  key   A
0  K0  A0
1  K1  A1
2  K2  A2
3  K3  A3
4  K4  A4
5  K5  A5
```

```pycon
>>> other = pd.DataFrame({"key": ["K0", "K1", "K2"], "B": ["B0", "B1", "B2"]})
```

```pycon
>>> other
  key   B
0  K0  B0
1  K1  B1
2  K2  B2
```

Join DataFrames using their indexes.

```pycon
>>> df.join(other, suffixes=("_caller", "_other"))
  key_caller   A key_other    B
0         K0  A0        K0   B0
1         K1  A1        K1   B1
2         K2  A2        K2   B2
3         K3  A3       NaN  NaN
4         K4  A4       NaN  NaN
5         K5  A5       NaN  NaN
```

If we want to join using the key columns, we need to set key to be
the index in both df and other. The joined DataFrame will have
key as its index.

```pycon
>>> df.set_index("key").join(other.set_index("key"))
      A    B
key
K0   A0   B0
K1   A1   B1
K2   A2   B2
K3   A3  NaN
K4   A4  NaN
K5   A5  NaN
```

Another option to join using the key columns is to use the on
parameter. DataFrame.join always uses other’s index but we can use
any column in df. This method preserves the original DataFrame’s
index in the result.

```pycon
>>> df.join(other.set_index("key"), on="key")
  key   A    B
0  K0  A0   B0
1  K1  A1   B1
2  K2  A2   B2
3  K3  A3  NaN
4  K4  A4  NaN
5  K5  A5  NaN
```

Using non-unique key values shows how they are matched.

```pycon
>>> df = pd.DataFrame(
...     {
...         "key": ["K0", "K1", "K1", "K3", "K0", "K1"],
...         "A": ["A0", "A1", "A2", "A3", "A4", "A5"],
...     }
... )
```

```pycon
>>> df
  key   A
0  K0  A0
1  K1  A1
2  K1  A2
3  K3  A3
4  K0  A4
5  K1  A5
```

```pycon
>>> df.join(other.set_index("key"), on="key", validate="m:1")
  key   A    B
0  K0  A0   B0
1  K1  A1   B1
2  K1  A2   B1
3  K3  A3  NaN
4  K0  A4   B0
5  K1  A5   B1
```

<!-- !! processed by numpydoc !! -->
