Index.to_numpy(dtype: Union[str, numpy.dtype, pandas.core.dtypes.base.ExtensionDtype, None] = None, copy: bool = False) → numpy.ndarray[source]

A NumPy ndarray representing the values in this Index or MultiIndex.


This method should only be used if the resulting NumPy ndarray is expected to be small, as all the data is loaded into the driver’s memory.

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. Note that copy=False does not ensure that to_numpy() is no-copy. Rather, copy=True ensures that a copy is made, even if not strictly necessary.



>>> ps.Series([1, 2, 3, 4]).index.to_numpy()
array([0, 1, 2, 3])
>>> ps.DataFrame({'a': ['a', 'b', 'c']}, index=[[1, 2, 3], [4, 5, 6]]).index.to_numpy()
array([(1, 4), (2, 5), (3, 6)], dtype=object)