builtins.object IntervalMixin Interval
class Interval(IntervalMixin):
Immutable object implementing an Interval, a bounded slice-like interval.
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.
See Also
--------
IntervalIndex : An Index of Interval objects that are all closed on the
same side.
cut : Convert continuous data into discrete bins (Categorical
of Interval objects).
qcut : Convert continuous data into bins (Categorical of Interval objects)
based on quantiles.
Period : Represents a period of time.
Notes
-----
The parameters `left` and `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'``).
Examples
--------
It is possible to build Intervals of different types, like numeric ones:
>>> iv = pd.Interval(left=0, right=5)
>>> iv
Interval(0, 5, closed='right')
You can check if an element belongs to it, or if it contains another interval:
>>> 2.5 in iv
True
>>> pd.Interval(left=2, right=5, closed='both') in iv
True
You can test the bounds (``closed='right'``, so ``0 < x <= 5``):
>>> 0 in iv
False
>>> 5 in iv
True
>>> 0.0001 in iv
True
Calculate its length
>>> iv.length
5
You can operate with `+` and `*` over an Interval and the operation
is applied to each of its bounds, so the result depends on the type
of the bound elements
>>> shifted_iv = iv + 3
>>> shifted_iv
Interval(3, 8, closed='right')
>>> 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
>>> 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
>>> year_2017.length
Timedelta('365 days 00:00:00')
| Signature du constructeur | Description |
|---|---|
| __new__(*args, **kwargs) | Create and return a new object. See help(type) for accurate signature. [extrait de __new__.__doc__] |
| __init__(self, /, *args, **kwargs) | Initialize self. See help(type(self)) for accurate signature. [extrait de __init__.__doc__] |
| Nom de l'attribut | Valeur |
|---|---|
| closed | <attribute 'closed' of 'pandas._libs.interval.Interval' objects> |
| left | <attribute 'left' of 'pandas._libs.interval.Interval' objects> |
| right | <attribute 'right' of 'pandas._libs.interval.Interval' objects> |
| Signature de l'opérateur | Description |
|---|---|
| __add__(self, value) | Return self+value. [extrait de __add__.__doc__] |
| __contains__(self, key) | Return bool(key in self). [extrait de __contains__.__doc__] |
| __eq__(self, value) | Return self==value. [extrait de __eq__.__doc__] |
| __floordiv__(self, value) | Return self//value. [extrait de __floordiv__.__doc__] |
| __ge__(self, value) | Return self>=value. [extrait de __ge__.__doc__] |
| __gt__(self, value) | Return self>value. [extrait de __gt__.__doc__] |
| __le__(self, value) | Return self<=value. [extrait de __le__.__doc__] |
| __lt__(self, value) | Return self<value. [extrait de __lt__.__doc__] |
| __mul__(self, value) | Return self*value. [extrait de __mul__.__doc__] |
| __ne__(self, value) | Return self!=value. [extrait de __ne__.__doc__] |
| __radd__(self, object) | |
| __rfloordiv__(self, value) | Return value//self. [extrait de __rfloordiv__.__doc__] |
| __rmul__(self, object) | |
| __rsub__(self, value) | Return value-self. [extrait de __rsub__.__doc__] |
| __rtruediv__(self, value) | Return value/self. [extrait de __rtruediv__.__doc__] |
| __sub__(self, value) | Return self-value. [extrait de __sub__.__doc__] |
| __truediv__(self, value) | Return self/value. [extrait de __truediv__.__doc__] |
| Signature de la méthode | Description |
|---|---|
| __hash__(self) | Return hash(self). [extrait de __hash__.__doc__] |
| __reduce__(self) | |
| __repr__(self) | |
| __str__(self) | Return str(self). [extrait de __str__.__doc__] |
| overlaps(self, other) |
Améliorations / Corrections
Vous avez des améliorations (ou des corrections) à proposer pour ce document : je vous remerçie par avance de m'en faire part, cela m'aide à améliorer le site.
Emplacement :
Description des améliorations :