-
pandas.merge_ordered(left, right, on=None, left_on=None, right_on=None, left_by=None, right_by=None, fill_method=None, suffixes=('_x', '_y'), how='outer')
[source] -
Perform merge with optional filling/interpolation 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 : 2-length sequence (tuple, list, ...)
Suffix to apply to overlapping column names in the left and right side, respectively
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)
New in version 0.19.0.
Returns: merged : DataFrame
The output type will the be same as ?left?, if it is a subclass of DataFrame.
See also
Examples
12345678>>> A >>> B
key lvalue group key rvalue
0
a
1
a
0
b
1
1
c
2
a
1
c
2
2
e
3
a
2
d
3
3
a
1
b
4
c
2
b
5
e
3
b
1234567891011121314>>> ordered_merge(A, B, fill_method
=
'ffill'
, left_by
=
'group'
)
key lvalue group rvalue
0
a
1
a NaN
1
b
1
a
1
2
c
2
a
2
3
d
2
a
3
4
e
3
a
3
5
f
3
a
4
6
a
1
b NaN
7
b
1
b
1
8
c
2
b
2
9
d
2
b
3
10
e
3
b
3
11
f
3
b
4
pandas.merge_ordered()

2025-01-10 15:47:30
Please login to continue.