polars.Series.to_pandas
-
Convert this Series to a pandas Series.
This operation copies data if
use_pyarrow_extension_arrayis 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
pandasandpyarroware installed.Examples
>>> s = pl.Series("a", [1, 2, 3]) >>> s.to_pandas() 0 1 1 2 2 3 Name: a, dtype: int64Null 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: float64Pass
use_pyarrow_extension_array=Trueto 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]
Series.to_pandas(
*,
use_pyarrow_extension_array: bool = False,
**kwargs: Any,
) → pd.Series[Any]
© 2020 Ritchie Vink
© 2022 Polars contributors
Licensed under the MIT License.
https://docs.pola.rs/api/python/stable/reference/series/api/polars.Series.to_pandas.html