Nearest Neighbor Algorithm (general nearest, forward-nearest, or backward-nearest)
code

Some of your program is copy-n-pasted code; there is an opportunity to refactor.

Your docstring offers little guidance on valid direction values. Consider using enum.Enum. If None becomes 0, then 1 and -1 could represent the directions, with delta multiplied by the sign, killing two cases with one stone.

The identifier res for result is pretty OK, but consider using an abbreviation like idx for index, clarifying that it is not the "value" that the docstring said would be computed. Better yet, turn it into a function that is documented to return an index, and push the print statements into a calling function.

crd = 'forward'


I'm willing to believe that "d" denotes "direction", but the "cr" part of that identifier is obscure.

algorithm


  if there are better approaches (in terms of speed) to achieve the same output


Your main function suggests that you will repeatedly interrogate a large (70k) sample with diverse search values. In which case your data structure is not well suited to your task.

You are forcing pandas to read all N values on each query. Don't do that.

Build a two-column copy of the input that stores (index, value). Sort it by value. So far the cost is N log N.

Now for each query, binary search for search_value to land on result_index, at cost of log N. The desired answer is at result_index, or the entry before it, or the entry after it. Then use the stored index to report the corresponding index in the original input data.