pandas.IntervalIndex¶
-
class
pandas.IntervalIndex[source]¶ Immutable index of intervals that are closed on the same side.
New in version 0.20.0.
Parameters: - data : array-like (1-dimensional)
Array-like 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.
- dtype : dtype or None, default None
If None, dtype will be inferred.
New in version 0.23.0.
- copy : bool, default False
Copy the input data.
- name : object, optional
Name to be stored in the index.
- verify_integrity : bool, default True
Verify that the IntervalIndex is valid.
See also
Index- The base pandas Index type.
Interval- A bounded slice-like interval; the elements of an IntervalIndex.
interval_range- Function to create a fixed frequency IntervalIndex.
cut- Bin values into discrete Intervals.
qcut- Bin values into equal-sized Intervals based on rank or sample quantiles.
Notes
See the user guide for more.
Examples
A new
IntervalIndexis typically constructed usinginterval_range():>>> pd.interval_range(start=0, end=5) IntervalIndex([(0, 1], (1, 2], (2, 3], (3, 4], (4, 5]], closed='right', dtype='interval[int64]')
It may also be constructed using one of the constructor methods:
IntervalIndex.from_arrays(),IntervalIndex.from_breaks(), andIntervalIndex.from_tuples().See further examples in the doc strings of
interval_rangeand the mentioned constructor methods.Attributes
leftReturn the left endpoints of each Interval in the IntervalIndex as an Index rightReturn the right endpoints of each Interval in the IntervalIndex as an Index closedWhether the intervals are closed on the left-side, right-side, both or neither midReturn the midpoint of each Interval in the IntervalIndex as an Index lengthReturn an Index with entries denoting the length of each Interval in the IntervalIndex is_emptyIndicates if an interval is empty, meaning it contains no points. is_non_overlapping_monotonicReturn True if the IntervalIndex is non-overlapping (no Intervals share points) and is either monotonic increasing or monotonic decreasing, else False is_overlappingReturn True if the IntervalIndex has overlapping intervals, else False. valuesReturn the IntervalIndex’s data as an IntervalArray. Methods
from_arrays(left, right[, closed, name, …])Construct from two arrays defining the left and right bounds. from_tuples(data[, closed, name, copy, dtype])Construct an IntervalIndex from an array-like of tuples from_breaks(breaks[, closed, name, copy, dtype])Construct an IntervalIndex from an array of splits. contains(self, other)Check elementwise if the Intervals contain the value. overlaps(self, other)Check elementwise if an Interval overlaps the values in the IntervalIndex. set_closed(self, closed)Return an IntervalIndex identical to the current one, but closed on the specified side to_tuples(self[, na_tuple])Return an Index of tuples of the form (left, right)