Visidata: [howto] more percentile aggregators

Created on 25 May 2020  路  2Comments  路  Source: saulpw/visidata

currently, there are only median, q3, q4, q5, and q10 aggregators offering percentiles (see #96 for the history here). i very often want to see a specific percentile that is not in this list, for instance, the p95, p99, p9999, etc. it would be nice to have generic aggregators that take a parameter somehow (i can imagine typing percentile(95) or percentile(99.9), although i can see why one would be hesitant to add a parser here - i don't know enough about the visidata model to know what an idiomatic solution would look like here). if that's not reasonable for the roadmap, i'd settle for having q100 available :)

question

Most helpful comment

@anjakefala recently added some documentation on how to add a custom aggregator:
https://github.com/saulpw/visidata/blob/develop/docs/customize.md#adding-custom-aggregators
Also the code is implemented here:
https://github.com/saulpw/visidata/blob/develop/visidata/aggregators.py

All 2 comments

@anjakefala recently added some documentation on how to add a custom aggregator:
https://github.com/saulpw/visidata/blob/develop/docs/customize.md#adding-custom-aggregators
Also the code is implemented here:
https://github.com/saulpw/visidata/blob/develop/visidata/aggregators.py

This already exists in 1.5.2; add this to your .visidatarc and you can use this command with percentile(95) as you imagine. Check out the provided aggregators.py:percentile(). It took me a couple of tries but it ultimately it was pretty straightforward:

Sheet.addCommand('', 'aggr-col-expr', 'expr=input("aggr expr: "); aggregators[expr]=eval(expr); addAggregators([cursorCol], [expr])', 'add expr (like "percentile(95)") to aggregators for current column')

You can also add your own aggregators, as shown by the aggregators.py code linked above. If you put this in your .visidatarc:

aggregator('irr', numpy.irr, 'internal rate of return')

Then you can use irr as an aggregator with the standard + (aggregate-col) command.

You can't use numpy.irr with the above aggr-col-expr command in 1.5.2, but in 2.0 you will be able to. For that matter we may try to fold aggr-col-expr into aggregate-col, since it's almost there anyway, but it warrants a bit more investigation.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

khughitt picture khughitt  路  14Comments

qrkourier picture qrkourier  路  16Comments

geekscrapy picture geekscrapy  路  12Comments

kovasap picture kovasap  路  13Comments

aborruso picture aborruso  路  12Comments