pandas.merge_asof() function in Python
This method is used to perform an asof merge. This is similar to a left-join except that we match on nearest key rather than equal keys. Both DataFrames must be sorted by the key.
Syntax : pandas.merge_asof(left, right, on=None, left_on=None, right_on=None, left_index=False, right_index=False, by=None, left_by=None, right_by=None, suffixes=(‘_x’, ‘_y’), tolerance=None, allow_exact_matches=True, direction=’backward’, )
- left, right : DataFrame
- on : label, Field name to join on. Must be found in both DataFrames.
- left_on : label, Field name to join on in left DataFrame.
- right_on : label, Field name to join on in right DataFrame.
- left_index : boolean, Use the index of the left DataFrame as the join key.
- right_index : boolean, Use the index of the right DataFrame as the join key.
Below is the implementation of the above method with some examples :
Example 1 :
Example 2 :
Example 3 :
Last Updated on October 23, 2021 by admin