Python | Pandas TimedeltaIndex.set_names

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.set_names() function is used to set new names on the given TimedeltaIndex object. The function defaults to returning new index object.

Syntax : TimedeltaIndex.set_names(names, level=None, inplace=False)



Parameters :
names : name(s) to set
level : If the index is a MultiIndex (hierarchical), level(s) to set (None for all levels). Otherwise level must be None
inplace : if True, mutates in place

Return : new index (of same type and class…etc) [if inplace, returns None]

Example #1: Use TimedeltaIndex.set_names() function to set the names of the given TimedeltaIndex object.

filter_none

edit
close

play_arrow

link
brightness_4
code

# importing pandas as pd
import pandas as pd
  
# Create the TimedeltaIndex object
tidx = pd.TimedeltaIndex(start ='11 days 22:14:12.001124', periods = 5, freq ='T')
  
# Print the TimedeltaIndex object
print(tidx)

chevron_right


Output :

Now we will use the TimedeltaIndex.set_names() function to set the name of the given TimedeltaIndex object.

filter_none

edit
close

play_arrow

link
brightness_4
code

# set the name of the object
tidx.set_names(names ='Sale_Point')

chevron_right


Output :

As we can see in the output, the TimedeltaIndex.set_names() function has returned a new object and it has also set the name of the returned object.
 
Example #2: Use TimedeltaIndex.set_names() function to set the names of the given TimedeltaIndex object.

filter_none

edit
close

play_arrow

link
brightness_4
code

# importing pandas as pd
import pandas as pd
  
# Create the TimedeltaIndex object
tidx = pd.TimedeltaIndex(start ='03 days 09:22:56', periods = 5, freq ='H')
  
# Print the TimedeltaIndex object
print(tidx)

chevron_right


Output :

Now we will use the TimedeltaIndex.set_names() function to set the name of the given TimedeltaIndex object.

filter_none

edit
close

play_arrow

link
brightness_4
code

# set the name of the object
tidx.set_names(names ='Purchase_Time')

chevron_right


Output :

As we can see in the output, the TimedeltaIndex.set_names() function has returned a new object and it has also set the name of the returned object.



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.