To check if an interval is empty if closed from both sides, use the interval.is_empty property. At first, import the required libraries −
import pandas as pd
Interval closed from the both sides. Interval set using the "closed" parameter with value "both"
interval = pd.Interval(0, 0, closed='both')
Display the interval
print("Interval...\n",interval)
Check whether interval is empty when it is closed from both sides. An Interval that contains a single point is not empty i.e. False is returned
print("\nIs Interval empty? \n",interval.is_empty)
Example
Following is the code
import pandas as pd # interval closed from the both sides # Interval set using the "closed" parameter with value "both" interval = pd.Interval(0, 0, closed='both') # display the interval print("Interval...\n",interval) # display the interval length print("\nInterval length...\n",interval.length) # check whether interval is empty when it is closed from both sides # An Interval that contains a single point is not empty i.e. False is returned print("\nIs Interval empty? \n",interval.is_empty)
Output
This will produce the following code
Interval... [0, 0] Interval length... 0 Is Interval empty? False