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 two 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 two other key steps are:
i
(addcol-incr
).gs
, thenf
to fill nulls.The expression for
first
isw[0] != w[1] if len(w) == 2 else True
.