I have following code:
df.loc[f"{lower_border_date}":f"{upper_border_date}"]
So I want to filter my dataframe on the datetimeIndex but I don't want to include the lower_border_date matches in the result. Anyone has an idea how to deal with this? Thanks!
CodePudding user response:
Few options:
- Filter based on index:
df.loc[(df.index > lower_border_date) & (df.index <= upper_border_date)]
Directly filtering and taking all indices where index is greater then lower_border_date
and less or equal to upper_border_date
- use
.drop
. Less nice in my opinion, but should work:
df.loc[f"{lower_border_date}":f"{upper_border_date}"].drop(index=lower_border_date)
- You can also use
pd.date_range
, filter the first date, and then use.loc
. It's also a weird workaround, but that is an option