pandas.IntervalIndex — pandas 3.0.1 documentation (original) (raw)
class pandas.IntervalIndex(data, closed=None, dtype=None, copy=None, name=None, verify_integrity=True)[source]#
Immutable index of intervals that are closed on the same side.
Parameters:
dataarray-like (1-dimensional)
Array-like (ndarray, DateTimeArray, TimeDeltaArray) containing Interval objects from which to build the IntervalIndex.
closed{‘left’, ‘right’, ‘both’, ‘neither’}, default ‘right’
Whether the intervals are closed on the left-side, right-side, both or neither.
dtypedtype or None, default None
If None, dtype will be inferred.
copybool, default None
Whether to copy input data, only relevant for array, Series, and Index inputs (for other input, e.g. a list, a new array is created anyway). Defaults to True for array input and False for Index/Series. Set to False to avoid copying array input at your own risk (if you know the input data won’t be modified elsewhere). Set to True to force copying Series/Index input up front.
nameobject, optional
Name to be stored in the index.
verify_integritybool, default True
Verify that the IntervalIndex is valid.
Attributes
Methods
See also
The base pandas Index type.
A bounded slice-like interval; the elements of an IntervalIndex.
Function to create a fixed frequency IntervalIndex.
Bin values into discrete Intervals.
Bin values into equal-sized Intervals based on rank or sample quantiles.
Notes
See the user guidefor more.
Examples
A new IntervalIndex is typically constructed usinginterval_range():
pd.interval_range(start=0, end=5) IntervalIndex([(0, 1], (1, 2], (2, 3], (3, 4], (4, 5]], dtype='interval[int64, right]')
It may also be constructed using one of the constructor methods: IntervalIndex.from_arrays(),IntervalIndex.from_breaks(), and IntervalIndex.from_tuples().
See further examples in the doc strings of interval_range and the mentioned constructor methods.