

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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 - Create an IntervalArray from an array of splits and check the intervals are closed on the left or right-side, both or neither
<p>To create an IntervalArray from an array of splits, use the <strong>pandas.arrays.IntervalArray.from_breaks().</strong></p><p>To check the intervals are closed on the left or right-side, both or neither, use the array.closed property.</p><p>At first, import the required libraries −</p><pre class="just-code notranslate language-python3" data-lang="python3">import pandas as pd</pre><p>Construct a new IntervalArray from an array-like of splits. The intervals are closed on the "right" by default −</p><pre class="just-code notranslate language-python3" data-lang="python3">array = pd.arrays.IntervalArray.from_breaks([0, 1, 2, 3, 4, 5]) </pre><p>Display the intervals −</p><pre class="just-code notranslate language-python3" data-lang="python3">print("Our IntervalArray... ",array)</pre><p>Check whether the intervals in the Interval Array is closed on the left-side, right-side, both or neither −</p><pre class="just-code notranslate language-python3" data-lang="python3">print(" Checking whether the intervals is closed... ",array.closed) </pre><h2>Example</h2><p>Following is the code −</p><pre class="demo-code notranslate language-python3" data-lang="python3">import pandas as pd # Construct a new IntervalArray from an array-like of splits # the intervals are closed on the "right" by default array = pd.arrays.IntervalArray.from_breaks([0, 1, 2, 3, 4, 5]) # Display the IntervalArray print("Our IntervalArray... ",array) # Getting the length of IntervalArray # Returns an Index with entries denoting the length of each Interval in the IntervalArray print(" Our IntervalArray length... ",array.length) # midpoint of each Interval in the IntervalArray as an Index print(" The midpoint of each interval in the IntervalArray... ",array.mid) # get the right endpoints print(" The right endpoints of each Interval in the IntervalArray as an Index... ",array.right) # check whether the intervals in the Interval Array is closed on the left-side, right-side, # both or neither print(" Checking whether the intervals is closed... ",array.closed)</pre><h2>Output</h2><p>This will produce the following code −</p><pre class="result notranslate">Our IntervalArray... <IntervalArray> [(0, 1], (1, 2], (2, 3], (3, 4], (4, 5]] Length: 5, dtype: interval[int64, right] Our IntervalArray length... Int64Index([1, 1, 1, 1, 1], dtype='int64') The midpoint of each interval in the IntervalArray... Float64Index([0.5, 1.5, 2.5, 3.5, 4.5], dtype='float64') The right endpoints of each Interval in the IntervalArray as an Index... Int64Index([1, 2, 3, 4, 5], dtype='int64') Checking whether the intervals is closed... Right</pre>
- Related Questions & Answers
- Python Pandas - Check whether the intervals in IntervalArray are closed on the left-side, right-side, both or neither
- Python Pandas - Check whether the IntervalIndex intervals are closed on the left-side, right-side, both or neither
- Python Pandas - Check whether the interval is closed on the left-side, right-side, both or neither
- Python Pandas - Construct an IntervalArray from an array of splits
- 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 - Return an IntervalArray identical to the current one but closed on 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
- 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 - Check elementwise if an Interval overlaps the values in the IntervalArray created from an array of splits
- Python Pandas - Return an IntervalArray identical to the current one but closed on the specified side
- Python Pandas IntervalArray - Check Intervals that only have an open endpoint in common overlap or not
- Python Pandas - Check if an interval is empty if closed from the both sides
Advertisements