Skip to content

Commit bf1a089

Browse files
authored
DOC: Additional "merge_asof" Docs Explaination (#62753)
1 parent ba84f84 commit bf1a089

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

pandas/core/reshape/merge.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -677,7 +677,9 @@ def merge_asof(
677677
Perform a merge by key distance.
678678
679679
This is similar to a left-join except that we match on nearest
680-
key rather than equal keys. Both DataFrames must be sorted by the key.
680+
key rather than equal keys. Both DataFrames must be first sorted by
681+
the merge key in ascending order before calling this function.
682+
Sorting by any additional 'by' grouping columns is not required.
681683
682684
For each row in the left DataFrame:
683685
@@ -700,19 +702,22 @@ def merge_asof(
700702
Second pandas object to merge.
701703
on : label
702704
Field name to join on. Must be found in both DataFrames.
703-
The data MUST be ordered. Furthermore this must be a numeric column,
704-
such as datetimelike, integer, or float. On or left_on/right_on
705-
must be given.
705+
The data MUST be in ascending order. Furthermore this must be
706+
a numeric column, such as datetimelike, integer, or float. ``on``
707+
or ``left_on`` / ``right_on`` must be given.
706708
left_on : label
707-
Field name to join on in left DataFrame.
709+
Field name to join on in left DataFrame. If specified, sort the left
710+
DataFrame by this column in ascending order before merging.
708711
right_on : label
709-
Field name to join on in right DataFrame.
712+
Field name to join on in right DataFrame. If specified, sort the right
713+
DataFrame by this column in ascending order before merging.
710714
left_index : bool
711715
Use the index of the left DataFrame as the join key.
712716
right_index : bool
713717
Use the index of the right DataFrame as the join key.
714718
by : column name or list of column names
715-
Match on these columns before performing merge operation.
719+
Match on these columns before performing merge operation. It is not required
720+
to sort by these columns.
716721
left_by : column name
717722
Field names to match on in the left DataFrame.
718723
right_by : column name
@@ -736,7 +741,8 @@ def merge_asof(
736741
Returns
737742
-------
738743
DataFrame
739-
A DataFrame of the two merged objects.
744+
A DataFrame of the two merged objects, containing all rows from the
745+
left DataFrame and the nearest matches from the right DataFrame.
740746
741747
See Also
742748
--------

0 commit comments

Comments
 (0)