0

I have a Dataframe with Timeindex and a Timeindex till which I want to slice the dataframe.

df[:upper_Timeindex_Timevalue]

The Question:

How do I get the element before this "limiting-index"?

df[:upper_Timeindex_Timevalue -1] # this wouldnt work this way bc timevalue +1 is not the next in dataframe

And how do I get the element after this "limiting-index"?

df[:upper_Timeindex_Timevalue +1] # this wouldnt work this way bc timevalue +1 is not the next in dataframe
Benoid
  • 209
  • 1
  • 4
  • 11

1 Answers1

1

You can use boolean indexing:

df.loc[df.index < upper_Timeindex_Timevalue].last()

or

df.loc[df.index > lower_Timeindex_TimeValue].first()
Quang Hoang
  • 146,074
  • 10
  • 56
  • 74