Skip to content

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

Closed
@dirkbike

Description

@dirkbike

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    AlgosNon-arithmetic algos: value_counts, factorize, sorting, isin, clip, shift, diffDatetimeDatetime data dtypeDuplicate ReportDuplicate issue or pull requestEnhancement

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions