I have a pandas dataframe like this:
col_name
0 -1
1 -1
2 -3
3 2
4 1
5 -3
6 -2
7 4
8 3
9 5
that could be created with the code:
import pandas as pd
df = pd.DataFrame(
{
'col_name': [-1, -1, -3, 2, 1, -3, -2, 4, 3, 5]
}
)
I want to find the rows that x rows before them and the row itself have positive values and y rows before those x rows have negative values and also the last row of these y rows which is actually y rows before the current row has the least value compared to k rows before of it.
So, for x=1, y=2 and k=2 the output is:
col_name
4 1
(Index 8 is not in the output because even though itself and one row before it have positive values, and two rows before them have negative values, but the last row with a negative value which is index 6, doesn't have the least value compared to two rows before itself.)
Also, it's my priority not to use any for-loops for the code.
Have you any idea about this?