drop(labels, axis)

def drop(self, 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
        Index or column labels to drop.
axis=0axis=1
删除行删除列

axis : int or axis name
Whether to drop labels from the index (0 / ‘index’) or
columns (1 / ‘columns’).

    index, columns : single label or list-like
        Alternative to specifying `axis` (``labels, axis=1`` is
        equivalent to ``columns=labels``).

        .. versionadded:: 0.21.0
    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.

    Returns
    -------
    dropped : type of caller

    Examples
    --------
    >>> df = pd.DataFrame(np.arange(12).reshape(3,4),
                          columns=['A', 'B', 'C', 'D'])
    >>> df
       A  B   C   D
    0  0  1   2   3
    1  4  5   6   7
    2  8  9  10  11

    Drop columns

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

    >>> df.drop(columns=['B', 'C'])
       A   D
    0  0   3
    1  4   7
    2  8  11

    Drop a row by index

    >>> df.drop([0, 1])
       A  B   C   D
    2  8  9  10  11

    Notes
    -----
    Specifying both `labels` and `index` or `columns` will raise a
    ValueError.

    """
KeyError Traceback (most recent call last) Cell In[17], line 1 ----> 1 data = data.drop(['125','125.1'],axis=1) 2 data File D:\anaconda\envs\zuoye\lib\site-packages\pandas\core\frame.py:5268, in DataFrame.drop(self, labels, axis, index, columns, level, inplace, errors) 5120 def drop( 5121 self, 5122 labels: IndexLabel = None, (...) 5129 errors: IgnoreRaise = "raise", 5130 ) -> DataFrame | None: 5131 """ 5132 Drop specified labels from rows or columns. 5133 (...) 5266 weight 1.0 0.8 5267 """ -> 5268 return super().drop( 5269 labels=labels, 5270 axis=axis, 5271 index=index, 5272 columns=columns, 5273 level=level, 5274 inplace=inplace, 5275 errors=errors, 5276 ) File D:\anaconda\envs\zuoye\lib\site-packages\pandas\core\generic.py:4549, in NDFrame.drop(self, labels, axis, index, columns, level, inplace, errors) 4547 for axis, labels in axes.items(): 4548 if labels is not None: -> 4549 obj = obj._drop_axis(labels, axis, level=level, errors=errors) 4551 if inplace: 4552 self._update_inplace(obj) File D:\anaconda\envs\zuoye\lib\site-packages\pandas\core\generic.py:4591, in NDFrame._drop_axis(self, labels, axis, level, errors, only_slice) 4589 new_axis = axis.drop(labels, level=level, errors=errors) 4590 else: -> 4591 new_axis = axis.drop(labels, errors=errors) 4592 indexer = axis.get_indexer(new_axis) 4594 # Case for non-unique axis 4595 else: File D:\anaconda\envs\zuoye\lib\site-packages\pandas\core\indexes\base.py:6696, in Index.drop(self, labels, errors) 6694 if mask.any(): 6695 if errors != "ignore": -> 6696 raise KeyError(f"{list(labels[mask])} not found in axis") 6697 indexer = indexer[~mask] 6698 return self.delete(indexer) KeyError: "['125', '125.1'] not found in axis"
06-11
--------------------------------------------------------------------------- KeyError Traceback (most recent call last) ~\AppData\Local\Temp\ipykernel_12396\356241790.py in <module> 3 if (df['应发库'][i]!="sz"and df['应发库'][i]!="cs"and df['应发库'][i]!="sy"and df['应发库'][i]!="sh"and df['应发库'][i]!="cd"and df['应发库'][i]!="xa"and df['应发库'][i]!="km"and df['应发库'][i]!="jn"and df['应发库'][i]!="bj"): 4 droplist.append(i) ----> 5 df2=df1.drop(labels=droplist,axis=0) ~\AppData\Local\anaconda3\envs\tensorflow\lib\site-packages\pandas\util\_decorators.py in wrapper(*args, **kwargs) 309 stacklevel=stacklevel, 310 ) --> 311 return func(*args, **kwargs) 312 313 return wrapper ~\AppData\Local\anaconda3\envs\tensorflow\lib\site-packages\pandas\core\frame.py in drop(self, labels, axis, index, columns, level, inplace, errors) 4911 level=level, 4912 inplace=inplace, -> 4913 errors=errors, 4914 ) 4915 ~\AppData\Local\anaconda3\envs\tensorflow\lib\site-packages\pandas\core\generic.py in drop(self, labels, axis, index, columns, level, inplace, errors) 4148 for axis, labels in axes.items(): 4149 if labels is not None: -> 4150 obj = obj._drop_axis(labels, axis, level=level, errors=errors) 4151 4152 if inplace: ~\AppData\Local\anaconda3\envs\tensorflow\lib\site-packages\pandas\core\generic.py in _drop_axis(self, labels, axis, level, errors) 4183 new_axis = axis.drop(labels, level=level, errors=errors) 4184 else: -> 4185 new_axis = axis.drop(labels, errors=errors) 4186 result = self.reindex(**{axis_name: new_axis}) 4187 ~\AppData\Local\anaconda3\envs\tensorflow\lib\site-packages\pandas\core\indexes\base.py in drop(self, labels, errors) 6015 if mask.any(): 6016 if errors != "ignore": -> 6017 raise KeyError(f"{labels[mask]} not found in axis") 6018 indexer = indexer[~mask] 6019 return self.delete(indexer) KeyError: '[357143] not found in axis'
06-03
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值