Table
#struct TableA data table with named columns, for machine learning.
| Name | Type | Description |
|---|---|---|
names | Vector<str> | The column names. |
kinds | Vector<int> | The kind of each column; one of the COL_ constants. |
cats | Vector<Vector<str>> | The levels of each categorical column. |
raw | Vector<Vector<str>> | The original text of the cells of COL_STR columns; empty for the other kinds. |
cells | matrix.Matrix | The numeric value of the cells; a categorical column holds the level number. |
import data
import matrix
func main throw:
text := "age,city,score,ok\n30,tehran,1.5,1\n25,shiraz,2.5,0\n41,tehran,3.0,1\n"
mut t := try data.LoadCsv(text, true)
println t.Rows(), t.Cols(), t.names, t.ColIndex("score"), t.ColIndex("x")
println t.kinds[0] == data.COL_INT,
t.kinds[1] == data.COL_CAT,
t.kinds[2] == data.COL_FLOAT,
data.COL_STR
println t.CatLevels("city")
mut m := t.ToMatrix()
println m.rows, m.cols, m.at(2, 1)
mut x := matrix.Matrix {}
mut y := matrix.Matrix {}
println t.SplitXy("ok", x, y), x.cols, y.at(1, 0)
try:
data.LoadCsvFile("missing.csv", true)
catch e:
println e.KindName(), e.path
end
matrix.Free(m)
matrix.Free(x)
matrix.Free(y)
t.Free()
end3 4 ["age", "city", "score", "ok"] 2 -1 true true true 3 ["tehran", "shiraz"] 3 4 0 true 3 0 not found missing.csv