pandas.api.extensions.ExtensionArray.to_numpy#

ExtensionArray.to_numpy(dtype=None, copy=False, na_value=<no_default>)[source]#

Convert to a NumPy ndarray.

This is similar to numpy.asarray(), but may provide additional control over how the conversion is done.

Parameters:
dtypestr or numpy.dtype, optional

The dtype to pass to numpy.asarray().

copybool, default False

Whether to ensure that the returned value is not a view on another array. copy=False avoids a copy when possible but does not guarantee a view.

na_valueAny, optional

The value to use for missing values. The default value depends on dtype and the type of the array.

Returns:
numpy.ndarray

The values of the array converted to dtype. When na_value is passed, missing values are replaced by it.

See also

Series.to_numpy

A NumPy ndarray representing the values in this Series.

Index.to_numpy

A NumPy ndarray representing the values in this Index.

Examples

>>> arr = pd.array([1, 2, pd.NA], dtype="Int64")
>>> arr.to_numpy()
array([ 1.,  2., nan])
>>> arr.to_numpy(dtype="object", na_value=None)
array([1, 2, None], dtype=object)