Build a column
Create a named column from Python values before building or modifying a DataFrame.
Polars · Class
polars.Series creates a one-dimensional, typed column from supported array-like data. You can provide its name and dtype, or let Polars infer the dtype from the values.
polars.Series constructs a typed, one-dimensional column from supported array-like input. You may provide a name and dtype; otherwise the name defaults to an empty string and the dtype is inferred from the values, with inference behavior controlled by strict.
polars.Series(name: str_ | ArrayLike | None = None, values: ArrayLike | None = None, dtype: PolarsDataType | None = None, *, strict: bool = True, nan_to_null: bool = False)| Name | Type | Description |
|---|---|---|
name | str_ | ArrayLike | None | Series name; used as the DataFrame column name, and defaults to an empty string when omitted. |
values | ArrayLike | None | One-dimensional input data; supported forms include a sequence, Series, PyArrow Array, or NumPy ndarray. |
dtype | PolarsDataType | None | Resulting Polars data type. If omitted, it is inferred from values. |
strict | bool | Controls strictness of type inference and conversion; defaults to True. |
nan_to_null | bool | For NumPy input, controls whether NaN values are converted to null; defaults to False and is ineffective for other inputs. |
A polars.Series object representing a single column.
nan_to_null only affects Series created from NumPy arrays.import polars as pl
s = pl.Series("values", [1, 2, 3])
print(s)
print(s.dtype)Creates a named Series from one-dimensional values; Polars infers the integer data type.
Create a named column from Python values before building or modifying a DataFrame.
Preserve a chosen Polars type instead of relying on input-based inference.
Convert NumPy NaN values to Polars nulls during construction.
Series represents a single column in a Polars DataFrame. It is one-dimensional and can be constructed from supported array-like inputs such as sequences, another Series, PyArrow arrays, or NumPy ndarrays.
Follow-up: How does dtype inference differ when strict is enabled? With strict inference, the inferred type follows the first non-null value; incompatible later values can raise an error.
The name argument supplies the Series name and becomes the column name when the Series is used in a DataFrame. If omitted, the name is an empty string.
Follow-up: What happens when the Series is inserted into a DataFrame without a name? It carries the empty-string name unless renamed before insertion.
dtype explicitly sets the resulting data type. When it is None, Polars infers the type from values; strict controls whether incompatible values cause failure or are converted to null where possible.
Follow-up: When would nan_to_null matter? It matters for NumPy input when NaN values should be represented as null; it has no effect on non-NumPy input.
polars.DataFramepolars.Series.itempolars.Series.__getitem__polars.Series.alias