Python | Pandas TimedeltaIndex.delete



TimedeltaIndex.delete() Pandas TimedeltaIndex.delete() creates a new DatetimeIndex with the deleted location. The function can delete more than one location at a time. It takes the index of the label to be removed as a parameter.

Syntax: TimedeltaIndex.delete (loc)

Parameters:
loc: Indicate which sub-arrays to remove.

Return: new_index: TimedeltaIndex

Example # 1: Use TimedeltaIndex.delete () to remove the passed index from the TimedeltaIndex object.

# import pandas as pd

import pandas as pd

 
# Create TimedeltaIndex object

tidx = pd.TimedeltaIndex (data = [ `06: 05: 01.000030` , ` +23: 59: 59.999999` ,

`22 day 2 min 3us 10ns` , None ])

 
# Print the TimedeltaIndex object

print (tidx)

Output:

Now we will use TimedeltaIndex.delete () to delete a value at the TimedeltaIndex.delete () index.

Note. The index value starts at 0.

# delete passed index

tidx.delete ( 1 )

Output:

As we can see from the output, TimedeltaIndex.delete () deleted the passed index and returned a new object.

Example # 2: Use TimedeltaIndex.delete () to remove the passed index from the TimedeltaIndex object .

# import pandas as pd

import pandas as pd

 
# Create first TimedeltaIndex object

tidx = pd.TimedeltaIndex (start = `1 days 02: 00: 12.001124` , periods = 8 ,

freq = `N` , name = `Koala` )

  
# Print the TimedeltaIndex object

print (tidx)

Output:

We will now use TimedeltaIndex.delete () to delete the passed index value.

Note. Index value starts at 0.

# remove passed indices

tidx.delete ([ 2 , 3 , 4 ])

Output:

As we can see in the output, TimedeltaIndex.delete () deleted the passed indices and returned a new object.