小编Mic*_*506的帖子

Python Pandas: Get rows where previous values are greater than 0

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 …

python dataframe pandas

2
推荐指数
1
解决办法
68
查看次数

标签 统计

dataframe ×1

pandas ×1

python ×1