Create tabular data
Turn dictionaries, sequences, or arrays into an eager table for analysis.
Polars · Class
polars.DataFrame constructs an eager two-dimensional table from common columnar or row-oriented inputs. It can infer the schema or use an explicitly declared schema, with optional control over orientation and inference depth.
Calling polars.DataFrame creates an eager, two-dimensional table from column-oriented or row-oriented input. Polars can infer column types, or you can provide a schema; when orientation is not specified, it infers the interpretation from the input dimensions and defaults to columns when that is inconclusive.
class polars.DataFrame(data=None, schema=None, *, schema_overrides=None, strict=True, orient=None, infer_schema_length=100, nan_to_null=False)| Name | Type | Description |
|---|---|---|
data | dict, Sequence, ndarray, Series, or pandas.DataFrame | Two-dimensional input; accepted forms include dict, sequence, ndarray, Series, or pandas.DataFrame. |
schema | Sequence of str, (str, DataType) pairs, or dict[str, DataType] | Schema supplied as column names, typed name/type pairs, or a name-to-type mapping. |
orient | {'col', 'row'} | None | Whether two-dimensional data is interpreted by columns or rows; defaults to inferred orientation. |
infer_schema_length | int | None | Maximum number of rows used for schema inference. |
A polars.DataFrame containing the supplied data with the resulting schema.
schema argument controls the resulting column names and data types.None, allowing Polars to infer those types.infer_schema_length limits how many rows Polars examines when inferring types.orient parameter explicitly selects column or row interpretation for two-dimensional input.import polars as pl
df = pl.DataFrame(
{"name": ["Ada", "Linus"], "years": [36, 55]},
schema={"name": pl.String, "years": pl.Int64},
)
print(df)Constructs a DataFrame from a dictionary and explicitly declares the column types.
Turn dictionaries, sequences, or arrays into an eager table for analysis.
Enforce names and Polars data types at construction time.
Load nested two-dimensional values whose row/column meaning is known.
Limit scanning cost or influence type inference for large inputs.
polars.DataFrame used for, and what inputs does its constructor accept?polars.DataFrame represents two-dimensional data as a table with rows and columns. Its constructor accepts dictionary, sequence, NumPy array, Series, or pandas DataFrame input.
Follow-up: How can construction control types? Supply a schema, such as a mapping from column names to Polars data types; unspecified types may be inferred.
The constructor can infer the schema from the input or use an explicitly supplied schema. A dictionary schema maps names to data types, while a list of names declares column names.
Follow-up: What happens when a mapping schema assigns None to a type? That type is auto-inferred from the corresponding data.
orient determines whether two-dimensional input is interpreted as columns or rows. If it is omitted, Polars compares column and data dimensions; if that is inconclusive, it uses column orientation.
Follow-up: When should orient="row" be selected? Use it when each inner sequence represents a row and dimension matching does not unambiguously establish that intent.
polars.Seriespolars.DataFrame.schemapolars.from_dataframe