本文共 1260 字,大约阅读时间需要 4 分钟。
Series.
drop
( labels=None, axis=0, index=None, columns=None, level=None, inplace=False, errors='raise' ) Return new object with labels in requested axis removed.
去除指定轴向的数据。以下参数操作灵活,可以有不同路径完成同一目的
Parameters: | labels : single label or list-like
axis : int or axis name
index, columns : single label or list-like
level : int or level name, default None
inplace : bool, default False
errors : {‘ignore’, ‘raise’}, default ‘raise’
|
---|---|
Returns: | dropped : type of caller |
Notes
Specifying both labels and index or columns will raise a ValueError.
Examples
>>> df = pd.DataFrame(np.arange(12).reshape(3,4), columns=['A', 'B', 'C', 'D'])>>> df A B C D0 0 1 2 31 4 5 6 72 8 9 10 11
Drop columns
>>> df.drop(['B', 'C'], axis=1) A D0 0 31 4 72 8 11
>>> df.drop(columns=['B', 'C']) A D0 0 31 4 72 8 11
Drop a row by index
>>> df.drop([0, 1]) A B C D2 8 9 10 11
转载地址:http://agmhl.baihongyu.com/