Interop with pandas tooling
Use pandas-only libraries or APIs that accept pandas.DataFrame rather than Polars DataFrame.
Polars · Module
Converts a Polars DataFrame to pandas. Enable PyArrow-backed extension arrays to preserve nulls and potentially avoid copying data.
Call this method on a Polars DataFrame to obtain a pandas DataFrame. By default, conversion uses NumPy-backed columns and copies data; enabling PyArrow-backed extension arrays can allow zero-copy conversion and preserve null values. Extra keyword arguments are forwarded to PyArrow's pandas conversion routine.
DataFrame.to_pandas(*, use_pyarrow_extension_array: bool = False, **kwargs: Any) → DataFrame| Name | Type | Description |
|---|---|---|
use_pyarrow_extension_array | bool = False | Choose PyArrow-backed extension arrays for pandas columns; this can preserve nulls and enable zero-copy conversion. |
**kwargs | Any | Additional options forwarded to pyarrow.Table.to_pandas(). |
pandas.DataFrame
import polars as pl
frame = pl.DataFrame({"value": [1, None], "label": ["a", "b"]})
pandas_frame = frame.to_pandas(use_pyarrow_extension_array=True)
print(pandas_frame)
print(pandas_frame.dtypes)Converts a Polars DataFrame while retaining missing values through PyArrow-backed pandas extension arrays.
Use pandas-only libraries or APIs that accept pandas.DataFrame rather than Polars DataFrame.
Retain missing values and reduce copying when transferring columns into pandas.
Pass supported PyArrow conversion settings for specialized pandas output.
The method returns a pandas.DataFrame created from the Polars DataFrame. Without the PyArrow extension option, the conversion copies data and numeric nulls become NaN.
Follow-up: How can null preservation be improved? Pass use_pyarrow_extension_array=True, which uses PyArrow-backed extension arrays and can also enable zero-copy conversion.
Set use_pyarrow_extension_array=True to use PyArrow-backed extension arrays rather than NumPy arrays. This can preserve null values and permit zero-copy conversion.
Follow-up: Is zero-copy guaranteed for all later pandas work? No; unsupported operations may cause conversion to NumPy.
The **kwargs parameter forwards additional keyword arguments to pyarrow.Table.to_pandas(). This lets callers configure the underlying PyArrow-to-pandas conversion.
Follow-up: What prerequisite does this imply? The environment must provide PyArrow, as well as pandas, because the method requires both packages.
polars.DataFrame.to_arrowpolars.from_pandaspolars.DataFrame.to_numpy