pandas 1.4.2

NotesParametersBackRef

Notes

The parameters :None:None:`left` and :None:None:`right` must be from the same type, you must be able to compare them and they must satisfy left <= right .

A closed interval (in mathematics denoted by square brackets) contains its endpoints, i.e. the closed interval [0, 5] is characterized by the conditions 0 <= x <= 5 . This is what closed='both' stands for. An open interval (in mathematics denoted by parentheses) does not contain its endpoints, i.e. the open interval (0, 5) is characterized by the conditions 0 < x < 5 . This is what closed='neither' stands for. Intervals can also be half-open or half-closed, i.e. [0, 5) is described by 0 <= x < 5 ( closed='left' ) and (0, 5] is described by 0 < x <= 5 ( closed='right' ).

Parameters

left : orderable scalar

Left bound for the interval.

right : orderable scalar

Right bound for the interval.

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

Whether the interval is closed on the left-side, right-side, both or neither. See the Notes for more detailed explanation.

Immutable object implementing an Interval, a bounded slice-like interval.

See Also

IntervalIndex

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

Period

Represents a period of time.

cut

Convert continuous data into discrete bins (Categorical of Interval objects).

qcut

Convert continuous data into bins (Categorical of Interval objects) based on quantiles.

Examples

It is possible to build Intervals of different types, like numeric ones:

This example is valid syntax, but we were not able to check execution
>>> iv = pd.Interval(left=0, right=5)
... iv Interval(0, 5, closed='right')

You can check if an element belongs to it

This example is valid syntax, but we were not able to check execution
>>> 2.5 in iv
True

You can test the bounds ( closed='right' , so 0 < x <= 5 ):

This example is valid syntax, but we were not able to check execution
>>> 0 in iv
False
This example is valid syntax, but we were not able to check execution
>>> 5 in iv
True
This example is valid syntax, but we were not able to check execution
>>> 0.0001 in iv
True

Calculate its length

This example is valid syntax, but we were not able to check execution
>>> iv.length
5

You can operate with :None:None:`+` and :None:None:`*` over an Interval and the operation is applied to each of its bounds, so the result depends on the type of the bound elements

This example is valid syntax, but we were not able to check execution
>>> shifted_iv = iv + 3
... shifted_iv Interval(3, 8, closed='right')
This example is valid syntax, but we were not able to check execution
>>> extended_iv = iv * 10.0
... extended_iv Interval(0.0, 50.0, closed='right')

To create a time interval you can use Timestamps as the bounds

This example is valid syntax, but we were not able to check execution
>>> year_2017 = pd.Interval(pd.Timestamp('2017-01-01 00:00:00'),
...  pd.Timestamp('2018-01-01 00:00:00'),
...  closed='left')
... pd.Timestamp('2017-01-01 00:00') in year_2017 True
This example is valid syntax, but we were not able to check execution
>>> year_2017.length
Timedelta('365 days 00:00:00')
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.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/_libs/interval.cpython-39-darwin.so#None
type: <class 'type'>
Commit: