Thursday, October 23, 2025
HomeLanguagesPython | Pandas TimedeltaIndex.argsort

Python | Pandas TimedeltaIndex.argsort

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.argsort() function returns the indices that would sort the index and its underlying data. By default the ordering is of non-decreasing order.

Syntax : TimedeltaIndex.argsort(*args, **kwargs)

Parameters : None

Return : array of indexes

Example #1: Use TimedeltaIndex.argsort() function to find the ordering of elements of the given TimedeltaIndex object that would sort the underlying data in the object.




# importing pandas as pd
import pandas as pd
  
# Create the first TimedeltaIndex object
tidx = pd.TimedeltaIndex(data =['22 day 2 min 3us 10ns',
                                '06:05:01.000030', 
                                '+23:59:59.999999'])
  
# Print the TimedeltaIndex object
print(tidx)


Output :

Now we will find the ordering of the elements which will actually sort the underlying data in the tidx object.




# return the ordering of indices
# which will sort the data
tidx.argsort()


Output :

As we can see in the output, the TimedeltaIndex.argsort() function has returned an array containing the indices value which will sort the underlying data of tidx object.
 
Example #2: Use TimedeltaIndex.argsort() function to find the ordering of elements of the given TimedeltaIndex object that would sort the underlying data in the object.




# importing pandas as pd
import pandas as pd
  
# Create the TimedeltaIndex object
tidx = pd.TimedeltaIndex(data =['-3 days 02:10:00', 
                                '1 days 06:05:01.000030', 
                                '1 days 02:00:00'], name ='MyObjejct')
  
# Print the TimedeltaIndex object
print(tidx)


Output :

Now we will find the ordering of the elements which will actually sort the underlying data in the tidx object.




# return the ordering of indices 
# which will sort the data
tidx.argsort()


Output :

As we can see in the output, the TimedeltaIndex.argsort() function has returned an array containing the indices value which will sort the underlying data of tidx object.

Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32361 POSTS0 COMMENTS
Milvus
88 POSTS0 COMMENTS
Nango Kala
6728 POSTS0 COMMENTS
Nicole Veronica
11892 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11954 POSTS0 COMMENTS
Shaida Kate Naidoo
6852 POSTS0 COMMENTS
Ted Musemwa
7113 POSTS0 COMMENTS
Thapelo Manthata
6805 POSTS0 COMMENTS
Umr Jansen
6801 POSTS0 COMMENTS