DataFrame
Builtin index · Collections & strings
result = DataFrame(name=values, ...)
Input: name, ... · Output: result
What it is
Each named argument is a column: values is either a numeric Vec / List of Str (a real column) or a scalar number/Str (broadcast to every row). Builds a Table from the named columns, in the order the arguments were written; a scalar/string column broadcasts to the row count set by whichever columns are actual vectors, and vector columns must all agree in length.
Overloads
One call shape — this function is not overloaded.
| Code | Input | Output | Description |
result = DataFrame(name=values, ...) | name — (default values)not documented yet... repeatablenot documented yet | result Table | Returns a Table. |
Examples
From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.
df = DataFrame(x=[1, 2, 3], y=[4, 5, 6])
print(df.nrows) # 3, same as nrow(df)
print(df.ncols) # 2, same as ncol(df)
3 2
from collections-strings
df = DataFrame(id=[1, 2, 3], name=["alu", "steel", "brass"])
print(at(df, 1)) # {id = 2, name = "steel"}
labeled = index(df, "name")
print(labeled)
grown = insert_row(df, 3, {id=4, name="glass"})
print(grown)
{id = 2, name = "steel"}
id name
-- -----
1 alu
2 steel
3 brass
id name
-- -----
1 alu
2 steel
3 brass
4 glassfrom collections-strings
df = DataFrame(x=[1, 2, 3, 4, 5], y=[10, 20, 30, 40, 50], label="sample")
print(nrow(df)) # 5
print(ncol(df)) # 3
tall = filter(df, df.x > 2)
xy = select(tall, "x", "y")
print(xy)
print(describe(df))
5
3
x y
- --
3 30
4 40
5 50
stat x y
----- -------- ---------
count 5 5
mean 3 30
std 1.581139 15.811388
min 1 10
25% 2 20
... 3 more linesfrom collections-strings
How it works
table(name=values, ...) / DataFrame(...) — columns come straight from the call's named arguments, in the order they were written (that's why style is an ordered Vec, not a HashMap: table column order is part of a table's identity).
From the note above this builtin in the interpreter, where the reasoning was written down as it was built.
See also
table — documented in the same entry.