Examples
Numeric start and end is supported.

In [1]:
import numpy as np
import pandas as pd
In [2]:
pd.interval_range(start=0, end=6)
Out[2]:
IntervalIndex([(0, 1], (1, 2], (2, 3], (3, 4], (4, 5], (5, 6]],
              closed='right',
              dtype='interval[int64]')

Additionally, datetime-like input is also supported.

In [3]:
pd.interval_range(start=pd.Timestamp('2019-02-02'),
                  end=pd.Timestamp('2019-02-04'))
Out[3]:
IntervalIndex([(2019-02-02, 2019-02-03], (2019-02-03, 2019-02-04]],
              closed='right',
              dtype='interval[datetime64[ns]]')

The freq parameter specifies the frequency between the left and right. endpoints of the individual intervals
within the IntervalIndex. For numeric start and end, the frequency must also be numeric.

In [4]:
pd.interval_range(start=1, periods=5, freq=1.2)
Out[4]:
IntervalIndex([(1.0, 2.2], (2.2, 3.4], (3.4, 4.6], (4.6, 5.8], (5.8, 7.0]],
              closed='right',
              dtype='interval[float64]')

Similarly, for datetime-like start and end, the frequency must be convertible to a DateOffset.

In [5]:
pd.interval_range(start=pd.Timestamp('2019-02-02'),
                  periods=4, freq='MS')
Out[5]:
IntervalIndex([(2019-03-01, 2019-04-01], (2019-04-01, 2019-05-01], (2019-05-01, 2019-06-01], (2019-06-01, 2019-07-01]],
              closed='right',
              dtype='interval[datetime64[ns]]')

Specify start, end, and periods; the frequency is generated automatically (linearly spaced).

In [6]:
pd.interval_range(start=0, end=5, periods=4)
Out[6]:
IntervalIndex([(0.0, 1.25], (1.25, 2.5], (2.5, 3.75], (3.75, 5.0]],
              closed='right',
              dtype='interval[float64]')

The closed parameter specifies which endpoints of the individual intervals within the IntervalIndex
are closed.

In [7]:
pd.interval_range(end=6, periods=6, closed='both')
Out[7]:
IntervalIndex([[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6]],
              closed='both',
              dtype='interval[int64]')