polars.Series.to_pandas#

Series.to_pandas(
*,
use_pyarrow_extension_array: bool = False,
**kwargs: Any,
) pd.Series[Any][source]#

Convert this Series to a pandas Series.

This operation copies data if use_pyarrow_extension_array is not enabled.

Parameters:
use_pyarrow_extension_array

Use a PyArrow-backed extension array instead of a NumPy array for the pandas Series. This allows zero copy operations and preservation of null values. Subsequent operations on the resulting pandas Series may trigger conversion to NumPy if those operations are not supported by PyArrow compute functions.

**kwargs

Additional keyword arguments to be passed to pyarrow.Array.to_pandas().

Returns:
pandas.Series

Notes

This operation requires that both pandas and pyarrow are installed.

Examples

>>> s = pl.Series("a", [1, 2, 3])
>>> s.to_pandas()
0    1
1    2
2    3
Name: a, dtype: int64

Null values are converted to NaN.

>>> s = pl.Series("b", [1, 2, None])
>>> s.to_pandas()
0    1.0
1    2.0
2    NaN
Name: b, dtype: float64

Pass use_pyarrow_extension_array=True to get a pandas Series backed by a PyArrow extension array. This will preserve null values.

>>> s.to_pandas(use_pyarrow_extension_array=True)
0       1
1       2
2    <NA>
Name: b, dtype: int64[pyarrow]