Table Of Contents

Search

Enter search terms or a module, class or function name.

pandas.Series.drop

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

Return new object with labels in requested axis removed.

Parameters:

labels : single label or list-like

axis : int or axis name

level : int or level name, default None

For MultiIndex

inplace : bool, default False

If True, do operation inplace and return None.

errors : {‘ignore’, ‘raise’}, default ‘raise’

If ‘ignore’, suppress error and existing labels are dropped.

New in version 0.16.1.

Returns:

dropped : type of caller

Examples

>>> df = pd.DataFrame([[1, 2, 3, 4],
...                    [5, 6, 7, 8],
...                    [9, 1, 2, 3],
...                    [4, 5, 6, 7]
...                   ],
...                   columns=list('ABCD'))
>>> df
    A   B   C   D
0   1   2   3   4
1   5   6   7   8
2   9   1   2   3
3   4   5   6   7

Drop a row by index

>>> df.drop([0, 1])
    A   B   C   D
2   9   1   2   3
3   4   5   6   7

Drop columns

>>> df.drop(['A', 'B'], axis=1)
    C   D
0   3   4
1   7   8
2   2   3
3   6   7
Scroll To Top