polars.from_records#

polars.from_records(data: Sequence[Sequence[Any]], columns: Sequence[str] | None = None, orient: Orientation | None = None, infer_schema_length: int | None = 50) DataFrame[source]#

Construct a DataFrame from a sequence of sequences. This operation clones data.

Note that this is slower than creating from columnar memory.

Parameters:
dataSequence of sequences

Two-dimensional data represented as a sequence of sequences.

columnsSequence of str, default None

Column labels to use for resulting DataFrame. Must match data dimensions. If not specified, columns will be named column_0, column_1, etc.

orient{None, ‘col’, ‘row’}

Whether to interpret two-dimensional data as columns or as rows. If None, the orientation is inferred by matching the columns and data dimensions. If this does not yield conclusive results, column orientation is used.

infer_schema_length

How many dictionaries/rows to scan to determine the data types if set to None all rows are scanned. This will be slow.

Returns:
DataFrame

Examples

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