r/Clojure • u/Virtual_Acanthaceae9 • Jul 09 '25
Clojure tablecloath percentiles
Hello!
I'm playing with tablecloath (and found it a great tool!) but struggling a bit with percentiles
I'm not getting how the tc/percentiles function works
I have a simple dataset with a column being numbers, and would like to calculate the 25th 50th and 75th percentile, but cannot get it work
Main issue is that it requires me to pass a "percentage" parameter that seems to be a list of the same size of the row in the dataset :\ I think I got this function totally wrong, but I cannot find any documentation around it in the official one
any help?
Thank you!
5
u/joinr Jul 10 '25 edited Jul 10 '25
As much as I like tablecloth after starting mainlining it since around january, I hit similar little gaps like this as well. IMO, the use case for tc/percentiles is pretty baffling (and the current docstring looks off)....I would expect something like this (and I'll probably put one in my growing utils for tablecloth stuff):
I think it's because it got exposed by accident during the column operators project. A bunch of stuff was auto-generated (e.g. lifted) from the column-wise operations into the tc dataset api, but there are no examples of them. I think this is one of those. If you dig down into the implementation, it eventually bottoms out at tech.v3.datatype.statistics/percentiles which makes perfect sense (for a collection/column of values). Issue updated.
2
u/hrrld Jul 10 '25
First thought:
2
u/the_d4rq1 Jul 10 '25 edited Jul 10 '25
I can't recall how I arrived at this solution, but I had issues with percentiles as well. In the following example, I was calculating statistics on ping latency from the column :latency-ms. I believe the tech.v3.datatype.functional/percentiles function takes a seq of percentiles ([95]), and returns a seq of those percentiles calculated. Since I only passed 1 percentile, I take it with first:
EDIT: Better minimalist example
1
u/fingertoe11 Jul 09 '25
It looks like the function's docstring refers you to the underlying java lib: https://commons.apache.org/proper/commons-math/javadocs/api-3.6.1/index.html