- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Python Pandas - Return an IntervalArray identical to the current one but closed on the left side
To return an IntervalArray identical to the current one but closed on the left side, use the set_closed() method with value left.
At first, import the required libraries −
import pandas as pd
Create IntervalArray −
index = pd.arrays.IntervalArray.from_breaks(range(5))
Display the interval −
print("IntervalIndex...\n",index)
Return an IntervalArray identical to the current one but closed on specified side i.e. "left" here −
print("\nResult...",index.set_closed('left'))
Example
Following is the code −
import pandas as pd # Create IntervalArray index = pd.arrays.IntervalArray.from_breaks(range(5)) # Display the interval print("IntervalIndex...\n",index) # Display the interval length print("\nIntervalIndex length...\n",index.length) # the left bound print("\nThe left bound for the IntervalIndex...\n",index.left) # the right bound print("\nThe right bound for the IntervalIndex...\n",index.right) # Return an IntervalArray identical to the current one but closed on specified # side i.e. "left" here print("\nResult...",index.set_closed('left'))
Output
This will produce the following output −
IntervalIndex... <IntervalArray> [(0, 1], (1, 2], (2, 3], (3, 4]] Length: 4, dtype: interval[int64, right] IntervalIndex length... Int64Index([1, 1, 1, 1], dtype='int64') The left bound for the IntervalIndex... Int64Index([0, 1, 2, 3], dtype='int64') The right bound for the IntervalIndex... Int64Index([1, 2, 3, 4], dtype='int64') Result... <IntervalArray> [[0, 1), [1, 2), [2, 3), [3, 4)] Length: 4, dtype: interval[int64, left]
- Related Articles
- Python Pandas - Return an IntervalArray identical to the current one but closed on the specified side
- Python Pandas - Check whether the intervals in IntervalArray are closed on the left-side, right-side, both or neither
- Python Pandas - Check if an Interval is closed on the left side
- Python Pandas - Create an IntervalArray from an array of splits and check the intervals are closed on the left or right-side, both or neither
- Python Pandas - Check whether the interval is closed on the left-side, right-side, both or neither
- python Pandas - Return the left endpoints of each Interval in the IntervalArray as an Index
- Python Pandas - Check whether the IntervalIndex intervals are closed on the left-side, right-side, both or neither
- Python Pandas - Check if an interval is empty if closed from the left side
- Python Pandas - Check if an Interval is closed on the right side
- Python Pandas - Construct an IntervalArray from an array of splits and return the left endpoints of each interval
- Python Pandas - Construct an IntervalArray from an array-like of tuples and return the left endpoints of each Interval
- Python Pandas - Return the midpoint of each Interval in the IntervalArray as an Index
- Python Pandas - Return the right endpoints of each Interval in the IntervalArray as an Index
- Python Pandas - Check if the interval is open on the left side
- Python Pandas - Return an Index with entries denoting the length of each Interval in the IntervalArray

Advertisements