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')
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 Pandas Series Notebooks from here.
Previous: Series containing counts of unique values in Pandas
Next: Series-droplevel() function
- New Content published on w3resource:
- HTML-CSS Practical: Exercises, Practice, Solution
- Java Regular Expression: Exercises, Practice, Solution
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework
- Angular - JavaScript Framework
- Vue - JavaScript Framework
- Jest - JavaScript Testing Framework