Index.delete()
Pandas Index.delete()
returns a new object with passed locations removed. We can pass more than one place to delete as a list.
Syntax: Index.delete (loc)
Parameters:
loc: Scalar / List of IndicesReturns: new_index: Index
Example # 1: Use Index.delete ()
to delete the first value in the index.
|
Output:
Let’s delete the month" January ". It’s at index 0, so we’ll pass 0 as an argument to the function.
|
Output:
As we can see in the output, the function returned an object with the first label removed.
Example # 2: Use Index.delete ()
to delete more than one shortcut in an index.
|
Output:
Let’s remove the second, third, fourth and fifth indexes from the index. We pass the list of values to remove to the function.
|
Output:
How we can see that the labels corresponding to the passed values in the index have been removed.