pandas.IntervalIndex.values#
- property IntervalIndex.values[source]#
Return an array representing the data in the Index.
Warning
We recommend using
Index.arrayorIndex.to_numpy(), depending on whether you need a reference to the underlying data or a NumPy array. The return type of.valuesdepends on the dtype: it is anumpy.ndarrayfor some dtypes (for exampleint64orfloat64) and anExtensionArrayfor others (for exampleinterval,category, or nullableInt64), which makes it harder to write code that works across dtypes.Index.arrayalways returns the underlying array as anExtensionArray, andIndex.to_numpy()always returns anumpy.ndarrayand acceptsdtype,copy, andna_valuearguments to control the conversion.Changed in version 3.0.0: The returned array is read-only.
- Returns:
- array: numpy.ndarray or ExtensionArray
See also
Index.arrayReference to the underlying data.
Index.to_numpyA NumPy array representing the underlying data.
Examples
For an
Indexbacked by a NumPy dtype such asint64,.valuesreturns anumpy.ndarray:>>> idx = pd.Index([1, 2, 3]) >>> idx Index([1, 2, 3], dtype='int64') >>> idx.values array([1, 2, 3])
For an
Indexbacked by an extension dtype such asinterval,.valuesreturns anExtensionArrayinstead, whileIndex.to_numpy()always returns anumpy.ndarray:>>> idx = pd.interval_range(start=0, end=5) >>> idx.values <IntervalArray> [(0, 1], (1, 2], (2, 3], (3, 4], (4, 5]] Length: 5, dtype: interval[int64, right] >>> idx.to_numpy() array([Interval(0, 1, closed='right'), Interval(1, 2, closed='right'), Interval(2, 3, closed='right'), Interval(3, 4, closed='right'), Interval(4, 5, closed='right')], dtype=object)