Movatterモバイル変換


[0]ホーム

URL:


Skip to main content
Ctrl+K

pandas.Interval#

classpandas.Interval#

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

Parameters:
leftorderable scalar

Left bound for the interval.

rightorderable 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 orneither. 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 parametersleft andright must be from the same type, you must beable to compare them and they must satisfyleft<=right.

A closed interval (in mathematics denoted by square brackets) containsits endpoints, i.e. the closed interval[0,5] is characterized by theconditions0<=x<=5. This is whatclosed='both' stands for.An open interval (in mathematics denoted by parentheses) does not containits endpoints, i.e. the open interval(0,5) is characterized by theconditions0<x<5. This is whatclosed='neither' stands for.Intervals can also be half-open or half-closed, i.e.[0,5) isdescribed by0<=x<5 (closed='left') and(0,5] isdescribed by0<x<=5 (closed='right').

Examples

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

>>>iv=pd.Interval(left=0,right=5)>>>ivInterval(0, 5, closed='right')

You can check if an element belongs to it, or if it contains another interval:

>>>2.5inivTrue>>>pd.Interval(left=2,right=5,closed='both')inivTrue

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

>>>0inivFalse>>>5inivTrue>>>0.0001inivTrue

Calculate its length

>>>iv.length5

You can operate with+ and* over an Interval and the operationis applied to each of its bounds, so the result depends on the typeof the bound elements

>>>shifted_iv=iv+3>>>shifted_ivInterval(3, 8, closed='right')>>>extended_iv=iv*10.0>>>extended_ivInterval(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')inyear_2017True>>>year_2017.lengthTimedelta('365 days 00:00:00')

Attributes

closed

String describing the inclusive side the intervals.

closed_left

Check if the interval is closed on the left side.

closed_right

Check if the interval is closed on the right side.

is_empty

Indicates if an interval is empty, meaning it contains no points.

left

Left bound for the interval.

length

Return the length of the Interval.

mid

Return the midpoint of the Interval.

open_left

Check if the interval is open on the left side.

open_right

Check if the interval is open on the right side.

right

Right bound for the interval.

Methods

overlaps(other)

Check whether two Interval objects overlap.


[8]ページ先頭

©2009-2025 Movatter.jp