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.