w3resource

Pandas Series: drop() function

Remove series with specified index labels

The drop() function is used to get series with specified index labels removed.

Remove elements of a Series based on specifying the index labels. When using a multi-index, labels on different levels can be removed by specifying the level.

Syntax:

Series.drop(self, labels=None, axis=0, index=None, columns=None, level=None, inplace=False, errors='raise')
Pandas Series drop image

Parameters:

Name Description Type/Default Value Required / Optional
labels Index labels to drop. single label or list-like Required
axis Redundant for application on Series. 0
Default Value: 0
Required
index, columns Redundant for application on Series, but index can be used instead of labels. Default Value: None Required
level For MultiIndex, level for which the labels will be removed. int or level name optional
inplace If True, do operation inplace and return None. bool
Default Value: False
Required
errors If ‘ignore’, suppress error and only existing labels are dropped. {‘ignore’, ‘raise’}
Default Value: ‘raise’
Required

Returns: Series
Series with specified index labels removed.

Raises: KeyError
If none of the labels are found in the index.

Example:


Download the above Notebook from here.



Inviting useful, relevant, well-written and unique guest posts