WIP: add convenience functions for selecting and sorting #26
WIP: add convenience functions for selecting and sorting #26keesterbrugge wants to merge 5 commits intosbelak:masterfrom
Conversation
Say I want to filter columns based on some predicate like a regular expression, whether it is an element of some collection of keywords or some composition of these. In this case it would be nice to have a function like `filter-cols` as it simplifies the code as follows:
From
``` clojure
(->> df
;; .. some transformation, perhaps new columns are added
(#(hc/select-cols (filter pred' (hc/cols %)) % )))
```
to
``` clojure
(->> df
;; .. some transformation, perhaps new columns are added
(filter-cols pred'))
```
I've also reimplemented `select-cols-regex` using this new function
|
I've added the function (->> df
;; change collection of columns in some way, e.g. using (derive-cols ...)
(#(select-cols (filter pred' (cols %)) % )))to (->> df
;; change collection of columns in some way, e.g. using (derive-cols ...)
(filter-cols pred'))I've reimplemented |
|
Thanks for this. I really like. A couple of things:
|
|
Thanks for your feedback :)
Question: |
|
3 reasons. In order of importance:
|
remove fn as it doesn't add enough value
|
That makes sense. I've added the function The benefit of (->> [{:a 1 :b 2}{:a 3 :b 10}]
(derive-cols* (ordered-map :c [inc :b]
:d [inc :c])))
;; => ({:a 1, :b 2, :c 3, :d 4} {:a 3, :b 10, :c 11, :d 12})or (->> [{:a 1 :b 2}{:a 3 :b 10}]
(derive-cols* [:c [inc :b]
:d [inc :c]])) instead of (->> [{:a 1 :b 2}{:a 3 :b 10}]
(derive-cols {:c [inc :b]})
(derive-cols {:d [inc :c]})) which becomes a bother when you have a long chain of new column derivations that have dependencies on each other. @sbelak What do you think? I don't know much about |
Hi @sbelak,
Thanks for this library! I've been getting a lot of mileage out of it. Here are some function that I use that might be a nice addition to your library:
select-cols-regex: function that selects columns using a regular expressioncompare-by: function that returns a comparator that makes sorting in a descending or ascending fashion per keyword easy. As opposed to the normal comparator it always sorts nil values last.Cheers!