

- 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 - Get the length of the Interval
To get the length of the Interval, use the interval.length property. At first, import the required libraries −
import pandas as pd
Open interval set using the "closed" parameter with value "neither". An open interval (in mathematics denoted by square brackets) does not contains its endpoints, i.e. the open interval [0, 5] is characterized by the conditions 0 < x < 5
interval = pd.Interval(5, 20, closed='neither')
Display the interval length
print("\nInterval length...\n",interval.length)
Example
Following is the code
import pandas as pd # Open interval set using the "closed" parameter with value "neither" # An open interval (in mathematics denoted by square brackets) does not contains its endpoints, # i.e. the open interval [0, 5] is characterized by the conditions 0 < x < 5. interval = pd.Interval(5, 20, closed='neither') # display the interval print("Interval...\n",interval) # the left bound print("\nThe left bound for the Interval...\n",interval.left) # the right bound print("\nThe right bound for the Interval...\n",interval.right) # display the interval length print("\nInterval length...\n",interval.length)
Output
This will produce the following code
Interval... (5, 20) The left bound for the Interval... 5 The right bound for the Interval... 20 Interval length... 15
- Related Questions & Answers
- Python Pandas - Get the left bound for the interval
- Python Pandas - Get the right bound for the interval
- Python Pandas - Get the length from the IntervalIndex
- Python Pandas - Return the midpoint of the Interval
- Python Pandas - Return an Index with entries denoting the length of each Interval in the IntervalArray
- Python Pandas - Check if the Pandas Index holds Interval objects
- Python Pandas - Get a tuple with the length of each level from MultiIndex
- Python Pandas IntervalIndex - Get the locations of all the relevant interval if a label is in several intervals
- Python Pandas - Get the second component of the Period
- Python Pandas - Return the midpoint of each Interval in the IntervalArray as an Index
- Python Pandas - Check if the interval is open on the left side
- Python Pandas - Check if the interval is open on the right side
- Python Pandas - Get the hour of the day component of the Period
- Python Pandas - Get the minute of the hour component of the Period
- Python Pandas - Get the month of the year component of the Period
Advertisements