polars.from_dict

polars.from_dict(data: Mapping[str, Union[Sequence, Mapping]], columns: Optional[Sequence[str]] = None) polars.internals.frame.DataFrame

Construct a DataFrame from a dictionary of sequences.

Parameters
datadict of sequences

Two-dimensional data represented as a dictionary. dict must contain Sequences.

columnsSequence of str, default None

Column labels to use for resulting DataFrame. If specified, overrides any labels already present in the data. Must match data dimensions.

Returns
DataFrame

Examples

>>> data = {"a": [1, 2], "b": [3, 4]}
>>> df = pl.from_dict(data)
>>> df
shape: (2, 2)
┌─────┬─────┐
│ a   ┆ b   │
│ --- ┆ --- │
│ i64 ┆ i64 │
╞═════╪═════╡
│ 1   ┆ 3   │
├╌╌╌╌╌┼╌╌╌╌╌┤
│ 2   ┆ 4   │
└─────┴─────┘