Skip to content

Idea for pandas.Index.nearest() method #7223

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
dirkbike opened this issue May 23, 2014 · 2 comments
Closed

Idea for pandas.Index.nearest() method #7223

dirkbike opened this issue May 23, 2014 · 2 comments
Labels
Algos Non-arithmetic algos: value_counts, factorize, sorting, isin, clip, shift, diff Datetime Datetime data dtype Duplicate Report Duplicate issue or pull request Enhancement

Comments

@dirkbike
Copy link

For an ordered index, there is a pandas.Index.asof() method that returns the most recent label to the label that's passed to it. However, in some cases it's useful to have a method that returns the nearest label to the label that is passed to it. For example:

>>> holidays = pandas.to_datetime(['2014-01-01','2014-01-20','2014-02-17'])
>>> print holidays.nearest('2014-01-15')
2014-01-20 00:00:00

Thoughts?

@jreback jreback added the Dupe label May 23, 2014
@jreback
Copy link
Contributor

jreback commented May 23, 2014

this is a dupe of #3004

thanks for this, I moved that other issue to 0.15. Interested in working on it?

@shoyer
Copy link
Member

shoyer commented Jul 30, 2014

I don't think this is exactly the same as #3004 or #7873.

  1. The other issues are about finding the nearest time, not nearest datetime.
  2. More generally, I would find a index.nearest() method useful for Float64Index as well as DatetimeIndex. Looking up nearest neighbors is a pretty common operation so it would be nice to have a shortcut for it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Algos Non-arithmetic algos: value_counts, factorize, sorting, isin, clip, shift, diff Datetime Datetime data dtype Duplicate Report Duplicate issue or pull request Enhancement
Projects
None yet
Development

No branches or pull requests

3 participants