Python Pandas - Check whether the IntervalIndex intervals are closed on the left-side, right-side, both or neither



To check whether the IntervalIndex intervals are closed on the left-side, right-side, both or neither, use the interval.closed property.

At first, import the required libraries −

import pandas as pd

Create IntervalIndex −

interval = pd.IntervalIndex.from_arrays([5, 10, 15], [15, 20, 25]) 

Display the interval −

print("IntervalIndex...\n",interval)

Check whether the IntervalIndex is closed on the left-side, right-side, both or neither −

print("\nChecking for the type of IntervalIndex...\n",interval.closed) 

Example

Following is the code −

import pandas as pd # Create IntervalIndex interval = pd.IntervalIndex.from_arrays([5, 10, 15], [15, 20, 25]) # Display the interval print("IntervalIndex...\n",interval) # Display the interval length print("\nIntervalIndex length...\n",interval.length) # Check whether the IntervalIndex is closed on the left-side, right-side, both or neither print("\nChecking for the type of IntervalIndex...\n",interval.closed)

Output

This will produce the following output −

IntervalIndex... IntervalIndex([(5, 15], (10, 20], (15, 25]], dtype='interval[int64, right]') IntervalIndex length... Int64Index([10, 10, 10], dtype='int64') Checking for the type of IntervalIndex... Right
Updated on: 2021-10-18T07:27:19+05:30

161 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements