Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric python packages. Pandas is one of those packages and makes importing and analyzing data much easier.
Pandas TimedeltaIndex.union() function is a specialized union for TimedeltaIndex objects. It combines overlapping ranges with the same DateOffset, will be much faster than Index.union
Syntax : TimedeltaIndex.union(other)
Parameters :Â
other : TimedeltaIndex or array-like
Return : Index or TimedeltaIndex
Â
Example #1: Use TimedeltaIndex.union() function to find the set union of two TimedeltaIndex objects.Â
Python3
# importing pandas as pdimport pandas as pd  
# Create the first TimedeltaIndex objecttidx1 = pd.TimedeltaIndex(start ='11 days 22:11:12.001124',                         periods = 5, freq ='T', name ='New_object')  
# Create the second TimedeltaIndex objecttidx2 = pd.TimedeltaIndex(start ='11 days 22:14:12.001124',                         periods = 5, freq ='T', name ='New_object')  
# Print the first TimedeltaIndex objectprint(tidx1)  
# Print the second TimedeltaIndex objectprint(tidx2) | 
Output :Â
Â
Now we will use the TimedeltaIndex.union() function to find the set union of the two objectsÂ
Python3
# find the uniontidx1.union(tidx2) | 
Output :Â
As we can see in the output, the TimedeltaIndex.union() function has returned an object which contains the union of both tidx1 and tidx2. 
  
Example #2: Use TimedeltaIndex.union() function to find the set union of two TimedeltaIndex objects. 
Python3
# importing pandas as pdimport pandas as pd  
# Create the first TimedeltaIndex objecttidx1 = pd.TimedeltaIndex(start ='1 days 02:00:12.001124',                         periods = 5, freq ='D', name ='Koala')  
# Create the second TimedeltaIndex objecttidx2 = pd.TimedeltaIndex(start ='3 days 02:00:12.001124',                         periods = 5, freq ='D', name ='Koala')  
# Print the first TimedeltaIndex objectprint(tidx1)  
# Print the second TimedeltaIndex objectprint(tidx2) | 
Output :Â
Â
Now we will use the TimedeltaIndex.union() function to find the set union of the two objectsÂ
Python3
# find the uniontidx1.union(tidx2) | 
Output :Â
As we can see in the output, the TimedeltaIndex.union() function has returned an object which contains the union of both tidx1 and tidx2.
 

                                    