Fork me on GitHub
#data-science
<
2022-09-29
>
Kamuela10:09:53

How do I get an individual field with tablecloth? I can only seem to narrow it down to a Column with 1 value

genmeblog12:09:17

What do you mean by 'individual field'? Dataset is a 2D table. Columns have names, rows have consecutive numbers.

genmeblog12:09:23

You can get row(s) as a map(s).

Kamuela12:09:52

(type (get (tc/last data) "final-column-name"))
=> tech.v3.dataset.impl.column.Column
What am I missing?

Kamuela12:09:19

I get [34.332] as a Column rather than 34.332 as a float

Kamuela12:09:14

And please correct my wording, if that's not called a field what is it more commonly called in tabular data?

genmeblog12:09:45

tc/last returns a dataset with one row (the last one). get returns a column which a seq

genmeblog12:09:08

Call first on the result.

Kamuela12:09:35

Is that not the equivalent of (get data 0)?

genmeblog12:09:35

(get data 0) will return a column with name 0

Kamuela12:09:51

Is the process we've outlined the canonical way of getting the artist formerly known as "field?"

Kamuela12:09:01

E.g. one cell

genmeblog12:09:41

There is no such function. You always end up with a column (a seq) or a row (as a map). Both are Clojure structures which you know how to deal with.

genmeblog12:09:50

I can add such function but it will be kind of redundant.

Kamuela12:09:01

Adding a specific function might be overkill, but maybe it needs to be a use case in the docs. If you have a general idea where it should be, I could add something if you like

genmeblog12:09:25

There is a section under dataset part which deals with accessing rows and cols in general. There can be a function like (tc/get dataset column row)

❤️ 1
genmeblog12:09:51

Maybe not get

Kamuela12:09:44

pluck, select-item, retrieve-item perhaps. I actually thought tc/select was going to do it given its signature at first glance

genmeblog12:09:59

Most of the functions in TC returns a dataset. Some of them escape to the clojure structures.

(def ds (tc/dataset {:a [1 2 3]
                   :b [99 98 97]
                   :c [:r :t :y]}))

(tc/rows ds) ;; returns vector of rows as vectors
;; => [[1 99 :r] [2 98 :t] [3 97 :y]]
(tc/rows ds :as-maps) ;; returns vector of rows as columns
;; => [{:a 1, :b 99, :c :r} {:a 2, :b 98, :c :t} {:a 3, :b 97, :c :y}]

(tc/columns ds) ;; returns sequence of columns
;; => [#tech.v3.dataset.column<int64>[3]
;;    :a
;;    [1, 2, 3] #tech.v3.dataset.column<int64>[3]
;;    :b
;;    [99, 98, 97] #tech.v3.dataset.column<keyword>[3]
;;    :c
;;    [:r, :t, :y]]

(tc/column ds :c) ;; returns column
;; => #tech.v3.dataset.column<keyword>[3]
;;    :c
;;    [:r, :t, :y]

;; column is a sequence
(seqable? (tc/column ds :c)) ;; => true
(first (tc/column ds :c)) ;; => :r

;; column is a vector
(sequential? (tc/column ds :c)) ;; => true
((tc/column ds :c) 0) ;; => :r

genmeblog12:09:33

I don't know why get-in doesn't work and probably this would be the best path for the data field selector.

metasoarous17:09:03

I think it would be great to have a fn along the lines of get-value or get-entry

genmeblog17:09:20

Oh! Good names, thanks.

chrisn16:10:50

Latest TMD does now support (issue above is fixed):

(get-in ds [cname field-idx])

👍 1
1
genmeblog19:10:46

tablecloth 6.101 landed on clojars with get-entry added https://scicloj.github.io/tablecloth/index.html#Single_entry

metal 1
thanks3 1
blueberry16:09:53

Just published new draft 0.29.0 of Deep Learning for Programmers 2.0. All existing v1.0 subscibers also get all these new updates. https://aiprobook.com/deep-learning-for-programmers/?release=0.30.0

👏 2
sheepy 1