Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Polars · Function

pl.from_pandas

Converts a pandas DataFrame, Series, or Index into a Polars DataFrame or Series. Optional controls handle schema overrides, rechunking, NaN-to-null conversion, and index inclusion.

How it works

The function eagerly converts a pandas DataFrame, Series, or Index into a Polars DataFrame or Series. It can override inferred schemas, normalize chunks, turn floating-point NaN values into nulls, and optionally include a meaningful pandas index as a column.

Syntax

polars.from_pandas(data: pd.DataFrame | pd.Series[Any] | pd.Index[Any] | pd.DatetimeIndex, *, schema_overrides: SchemaDict | None = None, rechunk: bool = True, nan_to_null: bool = True, include_index: bool = False) → DataFrame | Series

Parameters

NameTypeDescription
datapd.DataFrame | pd.Series[Any] | pd.Index[Any] | pd.DatetimeIndexPandas DataFrame, Series, Index, or DatetimeIndex to convert.
schema_overridesSchemaDict | NoneOptional mapping of column or field names to Polars data types.
rechunkboolWhether to rechunk the resulting data; defaults to true.
nan_to_nullboolWhether to convert NaN values to null; defaults to true.
include_indexboolWhether to include an eligible pandas index as a column; defaults to false.

Returns

A Polars DataFrame for pandas DataFrame input, or a Polars Series for pandas Series or Index input.

Key points

  • Use it to bridge common pandas tabular objects into Polars.
  • Use schema_overrides to specify desired Polars types instead of relying entirely on inference.
  • Rechunking is enabled by default, producing a consolidated memory layout.
  • Floating-point NaN values are converted to Polars null values by default.
  • Index inclusion is opt-in rather than the default behavior.
  • Conversion is not guaranteed to be zero-copy; account for possible data duplication.

Common mistakes

  • Both pandas and PyArrow must be installed before calling the function.
  • A default nameless pandas index is not included even when include_index=True; reset the index first if it must be preserved.
  • Because conversion may clone data, clone the resulting DataFrame when an independent copy is required.

Example: Convert a pandas DataFrame

import pandas as pd
import polars as pl

pdf = pd.DataFrame({"a": [1, 2], "b": ["x", "y"]})
df = pl.from_pandas(pdf, schema_overrides={"a": pl.Int32})
print(df)

Converts a pandas DataFrame to Polars while overriding the inferred type of column a.

When to use it

Convert existing pandas tables

Migrating a pandas pipeline to Polars

Override inferred schema

Enforcing a stable numeric or temporal dtype during ingestion

Import index metadata

Retaining a meaningful named pandas index during conversion

Interview questions

QWhat inputs and outputs does polars.from_pandas support?

It accepts a pandas DataFrame, Series, Index, or DatetimeIndex and returns the corresponding Polars DataFrame or Series. The conversion is eager and may clone data.

Follow-up: How would you preserve a meaningful pandas index? Set include_index=True; for a default nameless index, call pandas reset_index() before conversion.

QWhen would you use schema_overrides?

schema_overrides supplies explicit Polars dtypes for selected columns or fields, replacing inferred types for those entries. The other columns retain inferred schemas.

Follow-up: Why might explicit overrides matter? They make downstream typing predictable when pandas or Arrow inference produces an undesired dtype.

QWhat do the conversion options control?

rechunk=True requests contiguous memory for the resulting columns, while nan_to_null=True converts floating-point NaN values to Polars null values. include_index=True requests inclusion of a pandas index when it is eligible.

Follow-up: What is the limitation of include_index=True? It does not include a nameless default index; reset that index first.

  • polars.from_arrow
  • polars.from_dataframe
  • polars.DataFrame.clone
  • polars.DataFrame.reset_index

Source: polars.from_pandas — Polars documentation. Checked 2026-10-15.