pyspark.pandas.MultiIndex.to_numpy

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

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

Note

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.

Parameters
dtypestr or numpy.dtype, optional

The dtype to pass to numpy.asarray()

copybool, default False

Whether to ensure that the returned value is a 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.

Returns
numpy.ndarray

Examples

>>> 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)