The MATCH function in excel allows you to specify an optional set of parameters that will return either the largest value less than the specified value or the smallest value greater than the specified value.
For example, I have DataFrame, x.
In [1]: x = pd.DataFrame(data=list(range(0, 11)), columns=["Obs"])
In [2]: x
Out[2]:
Obs
0 0
1 1
2 2
3 3
4 4
5 5
6 6
7 7
8 8
9 9
10 10
And a data frame y.
In [3]: y = pd.DataFrame(data=[(-1, "Small"), (4, "Medium"), (7, "Large")],
columns=["Obs", "Cat"])
In [4]: y
Out[4]:
Obs Cat
0 -1 Small
1 4 Medium
2 7 Large
How can I make an INDEX-MATCH with match_type of 1, that is, it will go through each of the values in Obs and return the value "Cat", which corresponds to "Obs", which is the largest value, which is less and equal to the search?
Note that I would like to do this in some vector form and NOT write a user-defined function and iterate over the rows of the second DataFrame. That would be pretty inefficient.