pyspark.pandas.Series.drop#
- Series.drop(labels=None, index=None, columns=None, level=None, inplace=False)[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 removed by specifying the level.
- Parameters
- labelssingle label or list-like
Index labels to drop.
- indexsingle label or list-like
Redundant for application on Series, but index can be used instead of labels.
- columnssingle label or list-like
No change is made to the Series; use ‘index’ or ‘labels’ instead.
New in version 3.4.0.
- levelint 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
New in version 3.4.0.
- Returns
- Series
Series with specified index labels removed.
See also
Examples
>>> s = ps.Series(data=np.arange(3), index=['A', 'B', 'C']) >>> s A 0 B 1 C 2 dtype: int64
Drop single label A
>>> s.drop('A') B 1 C 2 dtype: int64
Drop labels B and C
>>> s.drop(labels=['B', 'C']) A 0 dtype: int64
With ‘index’ rather than ‘labels’ returns exactly same result.
>>> s.drop(index='A') B 1 C 2 dtype: int64
>>> s.drop(index=['B', 'C']) A 0 dtype: int64
With ‘columns’, no change is made to the Series.
>>> s.drop(columns=['A']) A 0 B 1 C 2 dtype: int64
With ‘inplace=True’, do operation inplace and return None.
>>> s.drop(index=['B', 'C'], inplace=True) >>> s A 0 dtype: int64
Also support for MultiIndex
>>> midx = pd.MultiIndex([['lama', 'cow', 'falcon'], ... ['speed', 'weight', 'length']], ... [[0, 0, 0, 1, 1, 1, 2, 2, 2], ... [0, 1, 2, 0, 1, 2, 0, 1, 2]]) >>> s = ps.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
>>> 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
>>> s.drop(('lama', 'weight')) lama speed 45.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
>>> s.drop([('lama', 'speed'), ('falcon', 'weight')]) lama weight 200.0 length 1.2 cow speed 30.0 weight 250.0 length 1.5 falcon speed 320.0 length 0.3 dtype: float64