huri icon indicating copy to clipboard operation
huri copied to clipboard

add function to rename cols

Open behrica opened this issue 8 years ago • 2 comments

I implemented it for me like this:

(defn rename-cols [renames df]
   (map #(clojure.set/rename-keys % renames) df)
  )

It is a rather trivial function, so I am not sure if you want to have it in huri.core.

If you are interested, I could make a PR

behrica avatar Sep 17 '17 15:09 behrica

Out of curiosity, what's the use case for renaming? I've never felt the need, but if I had to whip up something I'd probably use derive-cols with identity. Not categorically against including this, just want to understand the use cases better to see how widely applicable it is.

sbelak avatar Sep 18 '17 14:09 sbelak

I read my tables from csvs/excel and sometimes the column names are too ugyl.. Or I want to join, and need to make the join column the same name.

"derive" alone would not do it, as it needed 'derive' to make a copy and "select-cols" to remove the old one.

I am used to dplyr... so look for "similar" functions.

but indeed, rename coul be implemented by using derive + select. (to remove the former one)

behrica avatar Sep 18 '17 15:09 behrica