COUNTIF #2354
Replies: 3 comments 4 replies
-
I had a coffee and came up with this hack. It'd be nice to see if this could be made generically though, maybe work with other aggs? #/ COUNTIF
from collections import Counter
BaseSheet.addCommand(None, 'addcol-countif', 'sheet.countif = countif(cursorCol); addColumnAtCursor(ExprColumn("", "sheet.countif[curcol]", curcol=cursorCol, cache=True, type=int))')
@Sheet.api
def countif(vs, cursorCol):
c = Counter()
for typedvals in Progress(vs.iterdispvals(cursorCol), total=len(vs)):
c.update(typedvals.values())
return c
#/ How to make this more "visidatary"?! |
Beta Was this translation helpful? Give feedback.
-
I use For example, make an Another handy use of |
Beta Was this translation helpful? Give feedback.
-
Oh I see, you'd like the results to be updated as more rows are added. I'm not sure how to do that. Using aggregators won't work since they aren't recalculated when new rows are added. Perhaps look at visidata/visidata/experimental/rownum.py Line 42 in 7eeb719 |
Beta Was this translation helpful? Give feedback.
-
What would be the most efficient way to do an Excel-like COUNTIF on a column? (On the source sheet) I need to know how many of a column value is in the column
I appreciate I can do a freqsheet, but I essentially need the count values on the source sheet. What's the best way to do this?
(I would usually code something up but I can't really figure out the best starting point). It would probably use a cache, and like use
collections.Counter
I guess?Beta Was this translation helpful? Give feedback.
All reactions