pandas.DataFrame.merge

pandas 3.1.1 · DataFrame · method

Join tables by matching keys. Set how for the join type and validate to check the expected key relationship.

Call syntax

DataFrame.merge(…) Full signature
DataFrame.merge(
    right,
    how='inner',
    on=None,
    left_on=None,
    right_on=None,
    left_index=False,
    right_index=False,
    sort=False,
    suffixes=('_x', '_y'),
    copy=…,
    indicator=False,
    validate=None,
)

Run the example

Edit the example and select Run Python to see the result.

Parameters

ParameterRequirementAccepted values and behavior
right Required
Positional or keyword
DataFrame or named Series

Supply the right-hand input or the right endpoint of the interval.

how Optional
Positional or keyword
Default 'inner'
{'left', 'right', 'outer', 'inner', 'cross', 'left_anti', 'right_anti'}

Choose a policy such as a join type or a missing-value removal rule.

on Optional
Positional or keyword
Default None
Hashable or a sequence of the previous

Choose the shared key columns or name the axis column used by the operation.

left_on Optional
Positional or keyword
Default None
Hashable or a sequence of the previous, or array-like

Identify the join keys in the left-hand object.

right_on Optional
Positional or keyword
Default None
Hashable or a sequence of the previous, or array-like

Identify the join keys in the right-hand object.

left_index Optional
Positional or keyword
Default False
bool

Use the left object's index labels as join keys.

right_index Optional
Positional or keyword
Default False
bool

Use the right object's index labels as join keys.

sort Optional
Positional or keyword
Default False
bool

Choose whether the resulting labels or groups are sorted where supported.

suffixes Optional
Positional or keyword
Default ('_x', '_y')
list-like

Supply a pair for resolving duplicate column names in joined tables.

copy Optional
Positional or keyword
bool

Control whether data is copied where the API supports that choice.

indicator Optional
Positional or keyword
Default False
bool or str

Add an output column identifying which input supplied each joined row.

validate Optional
Positional or keyword
Default None
str

Check that key multiplicity matches the required relationship, such as "one_to_one" or "many_to_one".

Returns

DataFrame