Skip to main content
`Ctrl`+`K`

# pandas.arrays.IntervalArray

class pandas.arrays.IntervalArray(data, closed=None, dtype=None, copy=False, verify_integrity=True)

  Pandas array for interval data that are closed on the same side.

  An IntervalArray stores an array of Interval objects, where each Interval represents a contiguous span of values. All intervals in the array must have the same closure (left, right, both, or neither).

  Parameters:
    data array-like (1-dimensional)

      Array-like (ndarray, `DateTimeArray`, `TimeDeltaArray`) containing Interval objects from which to build the IntervalArray.

    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.

    copy bool, default False

      Copy the input data.

    verify_integrity bool, default True

      Verify that the IntervalArray is valid.

  Attributes

  `left` | Return the left endpoints of each Interval in the IntervalArray as an Index.
  `right` | Return the right endpoints of each Interval in the IntervalArray as an Index.
  `closed` | String describing the inclusive side the intervals.
  `mid` | Return the midpoint of each Interval in the IntervalArray as an Index.
  `length` | Return an Index with entries denoting the length of each Interval.
  `is_empty` | Indicates if an interval is empty, meaning it contains no points.
  `is_non_overlapping_monotonic` | Return a boolean whether the IntervalArray/IntervalIndex is non-overlapping and monotonic.

  Methods

  `from_arrays`(left, right[, closed, copy, dtype]) | Construct from two arrays defining the left and right bounds.
  `from_tuples`(data[, closed, copy, dtype]) | Construct an IntervalArray from an array-like of tuples.
  `from_breaks`(breaks[, closed, copy, dtype]) | Construct an IntervalArray from an array of splits.
  `contains`(other) | Check elementwise if the Intervals contain the value.
  `overlaps`(other) | Check elementwise if an Interval overlaps the values in the IntervalArray.
  `set_closed`(closed) | Return an identical IntervalArray closed on the specified side.
  `to_tuples`([na_tuple]) | Return an ndarray (if self is IntervalArray) or Index (if self is IntervalIndex) of tuples of the form (left, right).

  See also

  `Index`

    The base pandas Index type.

  `Interval`

    A bounded slice-like interval; the elements of an IntervalArray.

  `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 `IntervalArray` can be constructed directly from an array-like of `Interval` objects: >>> pd.arrays.IntervalArray([pd.Interval(0, 1), pd.Interval(1, 5)]) <IntervalArray> [(0, 1], (1, 5]] Length: 2, dtype: interval[int64, right]

  It may also be constructed using one of the constructor methods: `IntervalArray.from_arrays()`, `IntervalArray.from_breaks()`, and `IntervalArray.from_tuples()`.