def from_dicts(dicts: Sequence[Dict[str, Any]]) -> DataFrame: """ Construct a DataFrame from a sequence of dictionaries. Parameters ---------- dicts Sequence with dictionaries mapping column name to value Returns ------- DataFrame Examples -------- >>> data = [{"a": 1, "b": 4}, {"a": 2, "b": 5}, {"a": 3, "b": 6}] >>> df = pl.from_dicts(data) >>> df shape: (3, 2) ┌─────┬─────┐ │ a ┆ b │ │ --- ┆ --- │ │ i64 ┆ i64 │ ╞═════╪═════╡ │ 1 ┆ 4 │ ├╌╌╌╌╌┼╌╌╌╌╌┤ │ 2 ┆ 5 │ ├╌╌╌╌╌┼╌╌╌╌╌┤ │ 3 ┆ 6 │ └─────┴─────┘ """ return DataFrame._from_dicts(dicts)
def from_dicts(dicts: Sequence[dict[str, Any]], infer_schema_length: int | None = 50) -> DataFrame: """ Construct a DataFrame from a sequence of dictionaries. Parameters ---------- dicts Sequence with dictionaries mapping column name to value 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 = [{"a": 1, "b": 4}, {"a": 2, "b": 5}, {"a": 3, "b": 6}] >>> df = pl.from_dicts(data) >>> df shape: (3, 2) ┌─────┬─────┐ │ a ┆ b │ │ --- ┆ --- │ │ i64 ┆ i64 │ ╞═════╪═════╡ │ 1 ┆ 4 │ ├╌╌╌╌╌┼╌╌╌╌╌┤ │ 2 ┆ 5 │ ├╌╌╌╌╌┼╌╌╌╌╌┤ │ 3 ┆ 6 │ └─────┴─────┘ """ return DataFrame._from_dicts(dicts, infer_schema_length)