- 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 specified side
To return an IntervalArray identical to the current one but closed on the specified side, use the array.set_closed() with parameter both.
At first, import the required libraries −
import pandas as pd
Construct a new IntervalArray from an array-like of splits −
array = pd.arrays.IntervalArray.from_breaks([0, 1, 2, 3, 4, 5])
Display the intervals −
print("Our IntervalArray...\n",array)
An IntervalArray identical to the current one but closed on the specified side −
print("\nAn identical IntervalArray closed on the specified side...\n", array.set_closed('both'))
Example
Following is the code −
import pandas as pd # Construct a new IntervalArray from an array-like of splits array = pd.arrays.IntervalArray.from_breaks([0, 1, 2, 3, 4, 5]) # Display the IntervalArray print("Our IntervalArray...\n",array) print("\nAn identical IntervalArray closed on the specified side...\n", array.set_closed('both'))
Output
This will produce the following code −
Our IntervalArray... <IntervalArray> [(0, 1], (1, 2], (2, 3], (3, 4], (4, 5]] Length: 5, dtype: interval[int64, right] An identical IntervalArray closed on the specified side... <IntervalArray> [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5]] Length: 5, dtype: interval[int64, both]
- Related Articles
- Python Pandas - Return an IntervalArray identical to the current one but closed on the left 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 - Check if an Interval is closed on the right 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 - Return the midpoint of each Interval in the IntervalArray as an Index
- 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 - Return the right 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 - Return an Index with entries denoting the length of each Interval in the IntervalArray
- Python Pandas IntervalArray - Check Intervals that share closed endpoints overlap or not
- Python Pandas - Check if an interval is empty if closed from the left 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 of splits and return the right endpoints of each interval

Advertisements