pandas 1.4.2

ParametersReturnsBackRef
merge_ordered(left: 'DataFrame', right: 'DataFrame', on: 'IndexLabel | None' = None, left_on: 'IndexLabel | None' = None, right_on: 'IndexLabel | None' = None, left_by=None, right_by=None, fill_method: 'str | None' = None, suffixes: 'Suffixes' = ('_x', '_y'), how: 'str' = 'outer') -> 'DataFrame'

Designed for ordered data like time series data. Optionally perform group-wise merge (see examples).

Parameters

left : DataFrame
right : DataFrame
on : label or list

Field names to join on. Must be found in both DataFrames.

left_on : label or list, or array-like

Field names to join on in left DataFrame. Can be a vector or list of vectors of the length of the DataFrame to use a particular vector as the join key instead of columns.

right_on : label or list, or array-like

Field names to join on in right DataFrame or vector/list of vectors per left_on docs.

left_by : column name or list of column names

Group left DataFrame by group columns and merge piece by piece with right DataFrame.

right_by : column name or list of column names

Group right DataFrame by group columns and merge piece by piece with left DataFrame.

fill_method : {'ffill', None}, default None

Interpolation method for data.

suffixes : list-like, default is ("_x", "_y")

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

versionchanged
how : {'left', 'right', 'outer', 'inner'}, default 'outer'
  • left: use only keys from left frame (SQL: left outer join)

  • right: use only keys from right frame (SQL: right outer join)

  • outer: use union of keys from both frames (SQL: full outer join)

  • inner: use intersection of keys from both frames (SQL: inner join).

Returns

DataFrame

The merged DataFrame output type will the be same as 'left', if it is a subclass of DataFrame.

Perform a merge for ordered data with optional filling/interpolation.

See Also

merge

Merge with a database-style join.

merge_asof

Merge on nearest keys.

Examples

This example is valid syntax, but we were not able to check execution
>>> df1 = pd.DataFrame(
...  {
...  "key": ["a", "c", "e", "a", "c", "e"],
...  "lvalue": [1, 2, 3, 1, 2, 3],
...  "group": ["a", "a", "a", "b", "b", "b"]
...  }
... )
... df1 key lvalue group 0 a 1 a 1 c 2 a 2 e 3 a 3 a 1 b 4 c 2 b 5 e 3 b
This example is valid syntax, but we were not able to check execution
>>> df2 = pd.DataFrame({"key": ["b", "c", "d"], "rvalue": [1, 2, 3]})
... df2 key rvalue 0 b 1 1 c 2 2 d 3
This example is valid syntax, but we were not able to check execution
>>> merge_ordered(df1, df2, fill_method="ffill", left_by="group")
  key  lvalue group  rvalue
0   a       1     a     NaN
1   b       1     a     1.0
2   c       2     a     2.0
3   d       2     a     3.0
4   e       3     a     3.0
5   a       1     b     NaN
6   b       1     b     1.0
7   c       2     b     2.0
8   d       2     b     3.0
9   e       3     b     3.0
See :

Back References

The following pages refer to to this document either explicitly or contain code examples using this.

pandas.core.reshape.merge.merge_asof pandas.core.reshape.merge.merge pandas.core.reshape.merge.merge_ordered pandas.core.frame.DataFrame.merge

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


File: /pandas/core/reshape/merge.py#185
type: <class 'function'>
Commit: