polars.from_dict#

polars.from_dict(data: Mapping[str, Union[Sequence[object], Mapping[str, Sequence[object]]]], columns: Optional[Sequence[str]] = None) DataFrame[source]#

Construct a DataFrame from a dictionary of sequences.

This operation clones data, unless you pass in a Dict[str, pl.Series].

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   │
└─────┴─────┘