
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
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
Return IntervalArray Closed on Specified Side in Python Pandas
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]
Advertisements