Create a DataFrame from a JavaScript object
object or array of data
Optionaloptions: DataFrameOptions<Schema, any>options
> pl.DataFrame({ a: [1, 2, 3], b: ["a", "b", "c"] });
shape: (3, 2)
┌─────┬─────┐
│ a ┆ b │
│ --- ┆ --- │
│ f64 ┆ str │
╞═════╪═════╡
│ 1.0 ┆ a │
│ 2.0 ┆ b │
│ 3.0 ┆ c │
└─────┴─────┘
To specify a more detailed/specific frame schema you can supply the `schema` parameter with a dictionary of (name,dtype) pairs...
> const data = {col1: [0, 2], col2: [3, 7]}
> pl.DataFrame(data, { schema: { "col1": pl.Float32, "col2": pl.Int64}} );
shape: (2, 2)
┌──────┬──────┐
│ col1 ┆ col2 │
│ --- ┆ --- │
│ f32 ┆ i64 │
╞══════╪══════╡
│ 0.0 ┆ 3 │
│ 2.0 ┆ 7 │
└──────┴──────┘
* Constructing a DataFrame from a list of lists, row orientation and columns specified
* > const data = [[1, 2, 3], [4, 5, 6]];
* > pl.DataFrame(data, { columns: ["a", "b", "c"], orient: "row" });
shape: (2, 3)
┌─────┬─────┬─────┐
│ a ┆ b ┆ c │
│ --- ┆ --- ┆ --- │
│ f64 ┆ f64 ┆ f64 │
╞═════╪═════╪═════╡
│ 1.0 ┆ 2.0 ┆ 3.0 │
│ 4.0 ┆ 5.0 ┆ 6.0 │
└─────┴─────┴─────┘
* Constructing an empty DataFrame with a schema
* > const schema = {
s: pl.String,
b: pl.Bool,
i: pl.Int32,
d: pl.Datetime("ms"),
a: pl.Struct([
new pl.Field("b", pl.Bool),
new pl.Field("bb", pl.Bool),
new pl.Field("s", pl.String),
new pl.Field("x", pl.Float64),
]),
};
* > pl.DataFrame({}, { schema }) or pl.DataFrame(null, { schema }) or pl.DataFrame(underfined, { schema });
shape: (0, 5)
┌─────┬──────┬─────┬──────────────┬───────────┐
│ s ┆ b ┆ i ┆ d ┆ a │
│ --- ┆ --- ┆ --- ┆ --- ┆ --- │
│ str ┆ bool ┆ i32 ┆ datetime[ms] ┆ struct[0] │
╞═════╪══════╪═════╪══════════════╪═══════════╡
└─────┴──────┴─────┴──────────────┴───────────┘
Optionaloptions: DataFrameOptions<S, any>Optionaloptions: DataFrameOptions<Schema, any>
DataFrame constructor