table::frame
On this page
The table: named, ordered columns of one length, and the operations that only reshape rows or columns (selection, slicing, nulls).
Structs
TableSource
pub struct TableNamed, ordered columns of equal length. Copies share the columns; every operation returns a new table and leaves its input as it was.
use table::{col, Table};
let t = table::table!{
"city": ["Seoul", "Busan", "Seoul"],
"temp": [21.5, 24.0, 19.0],
};
let warm = try t.filter(col("temp") .> 20.0) catch _ { t };
assert(warm.nrows() == 2);
A table with no columns and no rows.
Sourcepub fn from_columns(§cols: List<(str, Column)>) throws (TableError) -> Table From
(name, column)pairs; every column must have one length and every name be new.nabiuse table::{Column, Table}; let t = try Table::from_columns([("x", Column::from([1, 2, 3]))]) catch _ { Table::new() }; assert(t.shape() == (3, 1));
Sourcepub fn from_rows(§names: List<str>, rows: List<List<Value>>) throws (TableError) -> Table Rows of cells against
names; each column's type comes from its cells (Column::from_values). A row of another length is an error naming it.nabiuse table::Value; let t = try table::Table::from_rows(["a", "b"], [[Value::Int(1), Value::Str("x")], [Value::Int(2), Value::Null]]) catch _ { table::Table::new() }; assert(t.column_at(1).null_count() == 1);The number of rows.
The number of columns.
(rows, columns).No rows.
The column names, in order.
Names and types.
The columns, in order.
Sourcepub fn index_of(§self, name: str) throws (TableError) -> usize The position of column
name.Whether there is a column
name.
Sourcepub fn column(§self, name: str) throws (TableError) -> Column Column
name; a missing name is an error that suggests the closest one.Column
k(panics pastncols(), as list indexing does).
Sourcepub fn f64(§self, name: str) throws (TableError) -> Array<f64, 1> Column
nameas anf64array (no copy for anf64column without nulls, so treat it as read-only; nulls read as NaN).nabilet t = table::table!{ "x": [1.0, 2.0, 3.0] }; let x = try t.f64("x") catch _ { [0.0] }; assert((x .* 2.0).sum() == 12.0);
Sourcepub fn i64(§self, name: str) throws (TableError) -> Array<i64, 1> Column
nameas ani64array (no copy, read-only).Row
i(panics pastnrows()).Every row, front to back.
Sourcepub fn get(§self, i: usize, name: str) throws (TableError) -> Value The cell at row
i, columnname.
Sourcepub fn with(§self, name: str, c: Column) throws (TableError) -> Table The table with column
nameset toc: replaced in place when it exists, else added at the end.nabiuse table::Column; let t = table::table!{ "a": [1, 2] }; let u = try t.with("b", Column::from([true, false])) catch _ { t }; assert(u.names() == ["a", "b"]);
Sourcepub fn with_column(§self, name: str, e: Expr) throws (TableError) -> Table The table with column
namecomputed fromeover this table (replaced when it exists).nabiuse table::col; let t = table::table!{ "x": [1.0, 2.0], "y": [10.0, 20.0] }; let u = try t.with_column("z", col("x") .* 2 .+ col("y")) catch _ { t }; assert(u.row(1).f64("z") == 24.0);
Sourcepub fn with_columns(§self, es: List<(str, Expr)>) throws (TableError) -> Table Several computed columns, each evaluated against this table.
Sourcepub fn select(§self, names: List<str>) throws (TableError) -> Table Only the columns
names, in that order.nabilet t = table::table!{ "a": [1], "b": [2], "c": [3] }; let u = try t.select(["c", "a"]) catch _ { t }; assert(u.names() == ["c", "a"]);
Sourcepub fn drop(§self, names: List<str>) throws (TableError) -> Table Every column except
names.
Sourcepub fn rename(§self, pairs: List<(str, str)>) throws (TableError) -> Table Rename columns by
(old, new)pairs.nabilet t = table::table!{ "a": [1] }; let u = try t.rename([("a", "id")]) catch _ { t }; assert(u.names() == ["id"]);The first
nrows (all when there are fewer).The last
nrows.Rows
start..end, clamped to the table; the columns share their buffers with this table.
Sourcepub fn take(§self, idx: List<usize>) throws (TableError) -> Table The rows at
idx, in that order (repeats allowed). An index past the end is an error.nrows drawn without replacement (all, shuffled, whennis at least the row count), reproducible for oneseed. Floyd's algorithm: O(n) draws, kept in draw order.nabilet t = table::table!{ "a": [1, 2, 3, 4, 5] }; assert(t.sample(3, 7).nrows() == 3);
Sourcepub fn filter(§self, e: Expr) throws (TableError) -> Table The rows where
eistrue(null counts asfalse).nabiuse table::col; let t = table::table!{ "x": [1, 5, 3], "tag": ["a", "b", "a"] }; let u = try t.filter(col("x") .> 2 .&& col("tag") .== "a") catch _ { t }; assert(u.nrows() == 1);
Sourcepub fn filter_by_column(§self, name: str) throws (TableError) -> Table The rows where boolean column
nameistrue.
Sourcepub fn filter_mask(§self, mask: Array<bool, 1>) throws (TableError) -> Table The rows where
maskistrue; its length must be the row count.The rows for which
keepistrue.nabilet t = table::table!{ "name": ["ann", "bob"] }; let u = t.filter_rows(|r| r.str("name").starts_with("b")); assert(u.nrows() == 1);
Sourcepub fn drop_nulls(§self, names: List<str> | none) throws (TableError) -> Table The table with the rows that have a null in any of
namesremoved (none: in any column).
Sourcepub fn fill_null(§self, name: str, v: Value) throws (TableError) -> Table The table with the nulls of column
namereplaced byv, which must fit its type.nabilet t = table::table!{ "x": [1.0, none, 3.0] }; let u = try t.fill_null("x", table::Value::Float(0.0)) catch _ { t }; assert(u.row(1).f64("x") == 0.0);
Sourcepub fn fill_forward(§self, name: str) throws (TableError) -> Table Nulls of column
namereplaced by the last value above them (still null before the first value).
Sourcepub fn cast(§self, name: str, t: DType) throws (TableError) -> Table The table with column
nameconverted tot(Column::cast).nabilet t = table::table!{ "zip": [1234, 501] }; let u = try t.cast("zip", table::DType::Str) catch _ { t }; assert(u.row(1).str("zip") == "501");
Sourcepub fn vstack(§self, o: Table) throws (TableError) -> Table This table's rows followed by
o's. Columns match by name (any order); both tables need the same names.nabilet a = table::table!{ "x": [1], "y": ["a"] }; let b = table::table!{ "y": ["b"], "x": [2] }; let c = try a.vstack(b) catch _ { a }; assert(c.nrows() == 2 && c.row(1).str("y") == "b");
Sourcepub fn hstack(§self, o: Table) throws (TableError) -> Table The columns of this table, then
o's; both need one row count and distinct names.
Sourcepub fn concat(§ts: List<Table>) throws (TableError) -> Table The tables' rows, one after another (
vstackof each).Distinct rows, first occurrence kept, in order.
Sourcepub fn unique_by(§self, names: List<str>) throws (TableError) -> Table Rows distinct in columns
names, first occurrence kept.
Trait implementations 1
impl PartialEq for Table
RowSource
pub struct RowOne row of a table, read by column name.
let t = table::table!{ "a": [1, 2], "b": ["x", "y"] };
let r = t.row(1);
assert(r.get("a") == table::Value::Int(2));
assert(r.str("b") == "y");
The row's position in its table.
The cell in column
name;Nullwhen there is no such column.The cell in column
k.Column
nameas a number,nonefor null, text or a missing column.Column
nameas an integer,nonefor null or another kind.Column
nameas text;""for null or a non-text cell.Every cell, in column order.