A NumPy ndarray representing the values in this Series or Index.
Parameters:
dtype: str or numpy.dtype, optional
The dtype to pass to numpy.asarray().
copy: bool, default False
Whether to ensure that the returned value is not a view on another array. Note that copy=False does not ensure that to_numpy() is no-copy. Rather, copy=True ensure that a copy is made, even if not strictly necessary.
na_value: Any, optional
The value to use for missing values. The default value depends on dtype and the type of the array.
﹡﹡kwargs
Additional keywords passed through to the to_numpy method of the underlying array (for extension arrays).
Returns:
numpy.ndarray
The NumPy ndarray holding the values from this Series or Index. The dtype of the array may differ. See Notes.
See also:
Series.array
Get the actual data stored within.
Index.array
Get the actual data stored within.
DataFrame.to_numpy
Similar method for DataFrame.
Notes:
The returned array will be the same up to equality (values equal in self will be equal in the returned array; likewise for values that are not equal). When self contains an ExtensionArray, the dtype may be different. For example, for a category-dtype Series, to_numpy() will return a NumPy array and the categorical dtype will be lost.
For NumPy dtypes, this will be a reference to the actual data stored in this Series or Index (assuming copy=False). Modifying the result in place will modify the data stored in the Series or Index (not that we recommend doing that).
For extension types, to_numpy()may require copying data and coercing the result to a NumPy type (possibly object), which may be expensive. When you need a no-copy reference to the underlying data, Series.array should be used instead.
This table lays out the different dtypes and default return types of to_numpy() for various dtypes within pandas.
>>> ser = pd.Series(pd.Categorical(["a", "b", "a"]))>>> ser.to_numpy()array(['a', 'b', 'a'], dtype=object)
Specify the dtype to control how datetime-aware data is represented. Use dtype=object to return an ndarray of pandas Timestamp objects, each with the correct tz.