Movatterモバイル変換


[0]ホーム

URL:


Skip to main content
Ctrl+K

pandas.Series.drop#

Series.drop(labels=None,*,axis=0,index=None,columns=None,level=None,inplace=False,errors='raise')[source]#

Return 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 removedby specifying the level.

Parameters:
labelssingle label or list-like

Index labels to drop.

axis{0 or ‘index’}

Unused. Parameter needed for compatibility with DataFrame.

indexsingle label or list-like

Redundant for application on Series, but ‘index’ can be used insteadof ‘labels’.

columnssingle label or list-like

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

levelint or level name, optional

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

inplacebool, 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.

Returns:
Series or None

Series with specified index labels removed or None ifinplace=True.

Raises:
KeyError

If none of the labels are found in the index.

See also

Series.reindex

Return only specified index labels of Series.

Series.dropna

Return series without null values.

Series.drop_duplicates

Return Series with duplicate values removed.

DataFrame.drop

Drop specified labels from rows or columns.

Examples

>>>s=pd.Series(data=np.arange(3),index=['A','B','C'])>>>sA  0B  1C  2dtype: int64

Drop labels B en C

>>>s.drop(labels=['B','C'])A  0dtype: int64

Drop 2nd level label in MultiIndex Series

>>>midx=pd.MultiIndex(levels=[['llama','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)>>>sllama   speed      45.0        weight    200.0        length      1.2cow     speed      30.0        weight    250.0        length      1.5falcon  speed     320.0        weight      1.0        length      0.3dtype: float64
>>>s.drop(labels='weight',level=1)llama   speed      45.0        length      1.2cow     speed      30.0        length      1.5falcon  speed     320.0        length      0.3dtype: float64

[8]ページ先頭

©2009-2025 Movatter.jp