The Pandas IntervalIndex function to_tuples() used to convert an array of tuples of the form (left, right). It return ndarray of tuples.
1 IntervalIndex.to_tuples(*args, **kwargs)
na_tuple : It is booelan value that specifies value is True, It returns nan as a tuple if True, (nan, nan), or just as the NA value, if False, nan.
*args : It specifies an additional arguments to be passed to the function.
**kwargs : it specifies an additional keywords to be passed to the function.
1 import pandas as pd
2
3 index = pd.IntervalIndex.from_arrays([0, 1, 2], [1, 2, 3])
4
5 print('The IntervalIndex object :')
6 print(index)
7
8 res = index.to_tuples()
9 print('The converted tuple :')
10 print(res)
In the above example, a IntervalIndex object is created by calling a function from_arrays(). A to_tuples() function is called that returns an array of tuples that includes intervals. The result is assign to variable that will be printed on console.
1 The IntervalIndex object :
2 IntervalIndex([(0, 1], (1, 2], (2, 3]], dtype='interval[int64, right]')
3
4 The converted tuple :
5 Index([(0, 1), (1, 2), (2, 3)], dtype='object')
Example 2
1 import pandas as pd
2
3 index = pd.IntervalIndex.from_arrays([10, 11,12], [11, 12, 13])
4
5 print('The IntervalIndex object :')
6 print(index)
7
8 res = index.to_tuples()
9 print('The converted tuple :')
10 print(res)
In the above example, a IntervalIndex object is created by calling a function from_arrays(). A to_tuples() function is called that returns an array of tuples that includes intervals. The result is assign to variable that will be print.
1 The IntervalIndex object :
2 IntervalIndex([(10, 11], (11, 12], (12, 13]], dtype='interval[int64, right]')
3
4 The converted tuple :
5 Index([(10, 11), (11, 12), (12, 13)], dtype='object')
Related options for your search