- Series.to_numpy(*args: Any, zero_copy_only: bool = False, writable: bool = False, use_pyarrow: bool = True) ndarray[Any, Any] [source]#
Convert this Series to numpy. This operation clones data but is completely safe.
If you want a zero-copy view and know what you are doing, use .view().
args will be sent to pyarrow.Array.to_numpy.
If True, an exception will be raised if the conversion to a numpy array would require copying the underlying data (e.g. in presence of nulls, or for non-primitive types).
For numpy arrays created with zero copy (view on the Arrow data), the resulting array is not writable (Arrow data is immutable). By setting this to True, a copy of the array is made to ensure it is writable.
Use pyarrow for the conversion to numpy.
>>> s = pl.Series("a", [1, 2, 3]) >>> arr = s.to_numpy() >>> arr array([1, 2, 3], dtype=int64) >>> type(arr) <class 'numpy.ndarray'>