Things on this page are fragmentary and immature notes/thoughts of the author. Please read with your own judgement!
:timing
:sccache 1
:dep polars = { version = "0.21.1", features = ["lazy", "parquet"] }use polars::prelude::*;
use polars::df;Construct DataFrames¶
Construct a DataFrame using the df macro.
// use macro
let df = df![
"names" => ["a", "b", "c"],
"values" => [1, 2, 3],
"values_nulls" => [Some(1), None, Some(3)]
].unwrap();
dfshape: (3, 3)
┌───────┬────────┬──────────────┐
│ names ┆ values ┆ values_nulls │
│ --- ┆ --- ┆ --- │
│ str ┆ i32 ┆ i32 │
╞═══════╪════════╪══════════════╡
│ a ┆ 1 ┆ 1 │
├╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
│ b ┆ 2 ┆ null │
├╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
│ c ┆ 3 ┆ 3 │
└───────┴────────┴──────────────┘Construct a polars DataFrame from a vector of Series.
let s1 = Series::new("names", &["a", "b", "c"]);
let s2 = Series::new("values", &[Some(1), None, Some(3)]);
let df = DataFrame::new(vec![s1, s2]).unwrap();
dfshape: (3, 2)
+-------+--------+
| names | values |
| --- | --- |
| str | i32 |
+=======+========+
| a | 1 |
+-------+--------+
| b | null |
+-------+--------+
| c | 3 |
+-------+--------+