This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-06-26
Channels
- # babashka (63)
- # beginners (27)
- # calva (17)
- # cider (1)
- # clojure (23)
- # clojure-europe (6)
- # clojure-norway (4)
- # clojurescript (9)
- # cursive (8)
- # data-oriented-programming (9)
- # data-science (7)
- # fulcro (14)
- # graalvm (3)
- # helix (3)
- # introduce-yourself (1)
- # jobs-discuss (7)
- # membrane (40)
- # missionary (4)
- # off-topic (32)
- # pathom (60)
- # react (6)
- # releases (2)
- # shadow-cljs (4)
Hi I'm checking out dataset. How do I group by a coll and then aggreate the values? here my naive first try:
(-> [{:a 10 :b "fo"}
{:a 10 :b "fa"}
{:a 10 :b "fa"}]
ds/->dataset
(ds/group-by-column :b)
(update-vals
(fn [ds]
(dfn/sum (ds :a)))))
{"fo" 10.0, "fa" 20.0}
Also, you can reach for tablecloth
aggregate: https://scicloj.github.io/tablecloth/index.html#Aggregate
That is one way that is easy in terms of code. The reductions namespace contains https://techascent.github.io/tech.ml.dataset/tech.v3.dataset.reductions.html#var-group-by-column-agg to do this that will be a bit faster as then we do the aggregation during the group-by reduction.

Awesome; Thanks! I've been writing more or less the exact same code, so good to know the faster way of doing this.
(reduce ... (ds/rows ds))
See the https://techascent.github.io/tech.ml.dataset/quick-reference.html for more.