pandas 1.4.2

ParametersRaisesReturnsBackRef
drop(self, labels=None, axis=0, index=None, columns=None, level=None, inplace=False, errors='raise') -> 'Series'

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.

Parameters

labels : single label or list-like

Index labels to drop.

axis : 0, default 0

Redundant for application on Series.

index : single label or list-like

Redundant for application on Series, but 'index' can be used instead of 'labels'.

columns : single label or list-like

No change is made to the Series; use 'index' or 'labels' instead.

level : int or level name, optional

For MultiIndex, level for which the labels will be removed.

inplace : bool, default False

If True, do operation inplace and return None.

errors : {'ignore', 'raise'}, default 'raise'

If 'ignore', suppress error and only existing labels are dropped.

Raises

KeyError

If none of the labels are found in the index.

Returns

Series or None

Series with specified index labels removed or None if inplace=True .

Return Series with specified index labels removed.

See Also

DataFrame.drop

Drop specified labels from rows or columns.

Series.drop_duplicates

Return Series with duplicate values removed.

Series.dropna

Return series without null values.

Series.reindex

Return only specified index labels of Series.

Examples

This example is valid syntax, but we were not able to check execution
>>> s = pd.Series(data=np.arange(3), index=['A', 'B', 'C'])
... s A 0 B 1 C 2 dtype: int64

Drop labels B en C

This example is valid syntax, but we were not able to check execution
>>> s.drop(labels=['B', 'C'])
A  0
dtype: int64

Drop 2nd level label in MultiIndex Series

This example is valid syntax, but we were not able to check execution
>>> midx = pd.MultiIndex(levels=[['lama', 'cow', 'falcon'],
...  ['speed', 'weight', 'length']],
...  codes=[[0, 0, 0, 1, 1, 1, 2, 2, 2],
...  [0, 1, 2, 0, 1, 2, 0, 1, 2]])
... s = pd.Series([45, 200, 1.2, 30, 250, 1.5, 320, 1, 0.3],
...  index=midx)
... s lama speed 45.0 weight 200.0 length 1.2 cow speed 30.0 weight 250.0 length 1.5 falcon speed 320.0 weight 1.0 length 0.3 dtype: float64
This example is valid syntax, but we were not able to check execution
>>> s.drop(labels='weight', level=1)
lama    speed      45.0
        length      1.2
cow     speed      30.0
        length      1.5
falcon  speed     320.0
        length      0.3
dtype: float64
See :

Back References

The following pages refer to to this document either explicitly or contain code examples using this.

pandas.core.series.Series.reset_index

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


File: /pandas/core/series.py#4674
type: <class 'function'>
Commit: