This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2024-04-18
Channels
- # babashka (12)
- # beginners (35)
- # biff (6)
- # calva (23)
- # cider (7)
- # clj-kondo (10)
- # cljs-dev (15)
- # clojure (81)
- # clojure-dev (2)
- # clojure-europe (13)
- # clojure-germany (1)
- # clojure-korea (2)
- # clojure-nl (1)
- # clojure-norway (19)
- # clojure-uk (7)
- # clojurescript (23)
- # core-typed (33)
- # cursive (7)
- # data-science (7)
- # datalevin (9)
- # hyperfiddle (1)
- # introduce-yourself (2)
- # malli (1)
- # matrix (17)
- # missionary (24)
- # music (1)
- # off-topic (15)
- # polylith (6)
- # reagent (10)
- # releases (5)
- # remote-jobs (1)
- # shadow-cljs (3)
- # squint (7)
- # xtdb (11)
- # yamlscript (6)
What is an idiomatic way to express this pandas instruction with tech.ml.dataset
?
ds[ds["Column A"]<5] = 42
Do you actually wish to mutate your dataset in-place like in pandas? Or to create a new dataset with the values less than 5 replaced with 42?
Good question, I am realizing I don't know what might be the most efficient way. The following does work:
(require '[tech.v3.dataset :as ds])
(def ds
(ds/->dataset {"Column A" (range 10)}))
(ds/column-map ds
"Column A"
#(if (< % 5) 42 %))
_unnamed [10 1]:
| Column A |
|---------:|
| 42 |
| 42 |
| 42 |
| 42 |
| 42 |
| 5 |
| 6 |
| 7 |
| 8 |
| 9 |
But there may be more efficient ways, if your dataset is big.If performance is not an issue, then I think the above is just fine.
It would be helpful to bring this discussion to the Clojurians Zulip chat. https://scicloj.github.io/docs/community/chat/ Some people there will benefit from this question and also probably help.