How to calculate a windowed rank function? #2280
-
Suppose I have some sorted data like this:
And I want to rank the items in order, but restart the rank each time the group changes:
Can I do this with Visidata? The closest I've gotten is using the Window function: =1 if test != test_previous else None This gives me the first value of each group, but doesn't give me the subsequent ranks. (Note, also working around #2279 by creating a new frozen column with |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hi, yes, you can do this with Visidata. It took me a while to remember how. I did it with your method: mark the start of the group. The other key steps are:
|
Beta Was this translation helpful? Give feedback.
Hi, yes, you can do this with Visidata. It took me a while to remember how. I did it with your method: mark the start of the group. The other key steps are:
i
(addcol-incr
). Rename that column toi
:^
i
a) Make a window with
addcol-window
to use the value of the previous row and the value on the current row:w
1 0
b) Then, make an expression coumn that will be called
first
. The expression to use has changed as of September 4, 2024.For older visidata versions than that, like visidata <= 3.0.2:
i) Make an expression column which will be called
first
:=
w[0] != w[1] if len(w) == 2 else True
and rename it:^
…