Let's say I have a DataFrame like this:
df A B 5 0 1 18 2 3 125 4 5 where 5, 18, 125 are the index
I'd like to get the line before (or after) a certain index. For instance, I have index 18 (eg. by doing df[df.A==2].index), and I want to get the line before, and I don't know that this line has 5 as an index.
2 sub-questions:
- How can I get the position of index
18? Something likedf.loc[18].get_position()which would return1so I could reach the line before withdf.iloc[df.loc[18].get_position()-1] - Is there another solution, a bit like options
-C,-Aor-Bwith grep ?