Table Of Contents

Search

Enter search terms or a module, class or function name.

pandas.IntervalIndex

class pandas.IntervalIndex[source]

Immutable Index implementing an ordered, sliceable set. IntervalIndex represents an Index of Interval objects that are all closed on the same side.

New in version 0.20.0.

Warning

The indexing behaviors are provisional and may change in a future version of pandas.

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.

name : object, optional

Name to be stored in the index.

copy : boolean, default False

Copy the meta-data

dtype : dtype or None, default None

If None, dtype will be inferred

..versionadded:: 0.23.0

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, qcut

Notes

See the user guide for more.

Examples

A new IntervalIndex is typically constructed using interval_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(), and IntervalIndex.from_tuples().

See further examples in the doc strings of interval_range and the mentioned constructor methods.

Attributes

closed Whether the intervals are closed on the left-side, right-side, both or neither
is_non_overlapping_monotonic Return True if the IntervalIndex is non-overlapping (no Intervals share points) and is either monotonic increasing or monotonic decreasing, else False
left Return the left endpoints of each Interval in the IntervalIndex as an Index
length Return an Index with entries denoting the length of each Interval in the IntervalIndex
mid Return the midpoint of each Interval in the IntervalIndex as an Index
right Return the right endpoints of each Interval in the IntervalIndex as an Index
values Return the IntervalIndex’s data as a numpy array of Interval objects (with dtype=’object’)

Methods

contains(key) Return a boolean indicating if the key is IN the index
from_arrays(left, right[, closed, name, …]) Construct from two arrays defining the left and right bounds.
from_breaks(breaks[, closed, name, copy, dtype]) Construct an IntervalIndex from an array of splits
from_tuples(data[, closed, name, copy, dtype]) Construct an IntervalIndex from a list/array of tuples
get_indexer(target[, method, limit, tolerance]) Compute indexer and mask for new index given the current index.
get_loc(key[, method]) Get integer location, slice or boolean mask for requested label.
Scroll To Top