小编kor*_*396的帖子

Pandas count values greater than current row in the last n rows

How to get count of values greater than current row in the last n rows?

Imagine we have a dataframe as following:

    col_a
0    8.4
1   11.3
2    7.2
3    6.5
4    4.5
5    8.9
Run Code Online (Sandbox Code Playgroud)

I am trying to get a table such as following where n=3.

    col_a   col_b
0     8.4       0
1    11.3       0
2     7.2       2
3     6.5       3
4     4.5       3
5     8.9       0
Run Code Online (Sandbox Code Playgroud)

Thanks in advance.

python dataframe pandas

7
推荐指数
1
解决办法
1429
查看次数

标签 统计

dataframe ×1

pandas ×1

python ×1