Skip to content

ENH: Add Series#between to DatetimeIndex #54094

@bollard

Description

@bollard

Feature Type

  • Adding new functionality to pandas

  • Changing existing functionality in pandas

  • Removing existing functionality in pandas

Problem Description

I would like to use Series#between on DatetimeIndex instances. Presumably this could also be extended to other Index types, but I am specifically only considering the DatetimeIndex case

Feature Description

import pandas as pd

t = pd.Timestamp.today()
ser = pd.Series(range(10), index=pd.date_range(t, periods=10))

ser.loc[ser.between(t, t + pd.offsets.BDay(1))]

Alternative Solutions

import pandas as pd

t = pd.Timestamp.today()
ser = pd.Series(range(10), index=pd.date_range(t, periods=10))

# current option 1
ser.loc[(ser.index >= t) & (ser.index <= t + pd.offsets.BDay(1))]

# current option 2
ser.loc[ser.index.to_series().between(t, t + pd.offsets.BDay(1))]

Additional Context

Purely convenience method / addition. Presumably could also be extended to the related between_time method.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DatetimeDatetime data dtypeEnhancementIndexRelated to the Index class or subclassesNeeds DiscussionRequires discussion from core team before further action

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions