Pandas class IntervalDtype() in Python
The Pandas class IntervalDtype() used to create an ExtensionDtype for Interval data. It is not an actual numpy dtype rather it is a duck type.
Syntax
 1 class pandas.IntervalDtype(subtype = None, closed = None)
subtype : It can be string or np.dtype of the Interval bounds.
IntervalDtype() object
 1 import pandas as pd
 2 
 3 idtype = pd.IntervalDtype(subtype = 'int64', closed = 'both')
 4 
 5 print('The extension dtype for Interval data :')
 6 print(idtype)
In the above example, an extension dtype is created by passing a subtype and closed. The result is assign to the variable that will be printed on console.
Output
 1 The extension dtype for Interval data :
 2 interval[int64, both]

Example 2 with close neither

Example 2 with close neither
 1 import pandas as pd
 2 
 3 idtype = pd.IntervalDtype(subtype = 'int64', closed = 'neither')
 4 
 5 print('The extension dtype for Interval data :')
 6 print(idtype)
In the above example, an extension dtype is created by passing a subtype and closed as neither. The result is assign to the variable that will be print.
Output
 1 The extension dtype for Interval data :
 2 interval[int64, neither]

Example 3 with close left

Example 3 with close left
 1 import pandas as pd
 2 
 3 idtype = pd.IntervalDtype(subtype = 'int64', closed = 'left')
 4 
 5 print('The extension dtype for Interval data :')
 6 print(idtype)
In the above example, an extension dtype is created by passing a subtype and closed as left. The result is assign to the variable that will be print.
Output
 1 The extension dtype for Interval data :
 2 interval[int64, left]

Example 4 with right

Example 4 with right
 1 import pandas as pd
 2 
 3 idtype = pd.IntervalDtype(subtype = 'int64', closed = 'right')
 4 
 5 print('The extension dtype for Interval data :')
 6 print(idtype)
In the above example, an extension dtype is created by passing a subtype and closed as right. The result is assign to the variable that will be print.
Output
 1 The extension dtype for Interval data :
 2 interval[int64, right]
Privacy Policy
Terms of Service
Disclaimer
Contact us
About us