I have this dataframe in pandas:
col1 col2
0 1 -0.5
1 2 -4.0
2 8 3.0
3 9 6.0
4 4 345.0
5 6 -7.0
6 7 3456.0
7 47 3.0
8 2 5.0
9 4 -78.0
Run Code Online (Sandbox Code Playgroud)
I want to return only these rows, where the "col2" values of the previous 3 rows are greater than 0. In this case:
5 6 -7.0
Run Code Online (Sandbox Code Playgroud)
and
9 4 -78.0
Run Code Online (Sandbox Code Playgroud)
I have tried it with rolling but cant find a way. Can …