pandas 1.4.2

NotesParametersReturnsBackRef
interval_range(start=None, end=None, periods=None, freq=None, name: 'Hashable' = None, closed='right') -> 'IntervalIndex'

Notes

Of the four parameters start , end , periods , and freq , exactly three must be specified. If freq is omitted, the resulting IntervalIndex will have periods linearly spaced elements between start and end , inclusively.

To learn more about datetime-like frequency strings, please see :None:None:`this link <https://pandas.pydata.org/pandas-docs/stable/user_guide/timeseries.html#offset-aliases>`.

Parameters

start : numeric or datetime-like, default None

Left bound for generating intervals.

end : numeric or datetime-like, default None

Right bound for generating intervals.

periods : int, default None

Number of periods to generate.

freq : numeric, str, or DateOffset, default None

The length of each interval. Must be consistent with the type of start and end, e.g. 2 for numeric, or '5H' for datetime-like. Default is 1 for numeric and 'D' for datetime-like.

name : str, default None

Name of the resulting IntervalIndex.

closed : {'left', 'right', 'both', 'neither'}, default 'right'

Whether the intervals are closed on the left-side, right-side, both or neither.

Returns

IntervalIndex

Return a fixed frequency IntervalIndex.

See Also

IntervalIndex

An Index of intervals that are all closed on the same side.

Examples

Numeric start and end is supported.

This example is valid syntax, but we were not able to check execution
>>> pd.interval_range(start=0, end=5)
IntervalIndex([(0, 1], (1, 2], (2, 3], (3, 4], (4, 5]],
              dtype='interval[int64, right]')

Additionally, datetime-like input is also supported.

This example is valid syntax, but we were not able to check execution
>>> pd.interval_range(start=pd.Timestamp('2017-01-01'),
...  end=pd.Timestamp('2017-01-04')) IntervalIndex([(2017-01-01, 2017-01-02], (2017-01-02, 2017-01-03], (2017-01-03, 2017-01-04]], dtype='interval[datetime64[ns], right]')

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.

This example is valid syntax, but we were not able to check execution
>>> pd.interval_range(start=0, periods=4, freq=1.5)
IntervalIndex([(0.0, 1.5], (1.5, 3.0], (3.0, 4.5], (4.5, 6.0]],
              dtype='interval[float64, right]')

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

This example is valid syntax, but we were not able to check execution
>>> pd.interval_range(start=pd.Timestamp('2017-01-01'),
...  periods=3, freq='MS') IntervalIndex([(2017-01-01, 2017-02-01], (2017-02-01, 2017-03-01], (2017-03-01, 2017-04-01]], dtype='interval[datetime64[ns], right]')

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

This example is valid syntax, but we were not able to check execution
>>> pd.interval_range(start=0, end=6, periods=4)
IntervalIndex([(0.0, 1.5], (1.5, 3.0], (3.0, 4.5], (4.5, 6.0]],
          dtype='interval[float64, right]')

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

This example is valid syntax, but we were not able to check execution
>>> pd.interval_range(end=5, periods=4, closed='both')
IntervalIndex([[1, 2], [2, 3], [3, 4], [4, 5]],
              dtype='interval[int64, both]')
See :

Back References

The following pages refer to to this document either explicitly or contain code examples using this.

pandas.core.arrays.interval.IntervalArray pandas.core.indexes.datetimes.date_range pandas.core.indexes.interval.IntervalIndex

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


File: /pandas/core/indexes/interval.py#951
type: <class 'function'>
Commit: