This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-08-30
Channels
- # announcements (12)
- # babashka (25)
- # biff (30)
- # cherry (34)
- # cider (46)
- # clj-kondo (23)
- # clojure (37)
- # clojure-berlin (6)
- # clojure-europe (12)
- # clojure-nl (4)
- # clojure-norway (6)
- # clojure-uk (2)
- # clojurescript (8)
- # conjure (1)
- # cursive (4)
- # data-science (11)
- # datalevin (12)
- # datascript (15)
- # emacs (2)
- # events (1)
- # fulcro (14)
- # graalvm (16)
- # gratitude (23)
- # honeysql (11)
- # jobs (2)
- # jobs-discuss (14)
- # kaocha (1)
- # leiningen (8)
- # nbb (45)
- # off-topic (7)
- # portal (8)
- # re-frame (9)
- # releases (2)
- # shadow-cljs (24)
- # squint (5)
- # tools-build (17)
- # tools-deps (7)
- # vim (5)
When using tablecloth, can you select columns by index rather than by name? Something like (tc/select-columns #{1 2 3 4 5} ds)
I found this in the docs, and note the "not recommended"
> Select one column using an index (not recommended)
> (nth (tc/columns DS :as-seq) 2) ;; as column (iterable)
Ok, columns are stored in the list. So when you call (tc/columns ds :as-seq)
you'll get the java.util.List
and you can use nth
on this. I cannot guarantee that the order after set of operations is persisted. The API provides selection by name only.
I'm unclear as to why you would want to do this, but an obvious trick would be to have your own slim wrapper function over tc/select-columns for this plus a map of int->colname. This would work even if order is not preserved after some set of operations.
also you are likely to have better (certainly quicker) response in https://clojurians.zulipchat.com/#narrow/stream/151924-data-science/topic/tech.2Eml.2Edataset
@U06C63VL4 it's a situation where the tabular data coming in doesn't have a headers column, so I'm trying to figure out the best way to add such a thing with tc
There are two ways to handle that:
1. Go into the data and add a column header row - assuming this is csv/tsv
2. Specify the :header-row? false
option. This will cause each column to have a name of this format column-x
, where x is an integer. So, column-1, column-2
, etc. You can then use tc/rename-columns
to rename these to whatever you want