-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP: add convenience functions for selecting and sorting #26
base: master
Are you sure you want to change the base?
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!