我有一个dataframe,它有日期、销售和预算作为列名。我想删除date列,但它给出了一个错误 KeyError: "['Date'] not found in axis"
KeyError: "['Date'] not found in axis"
下面是我的代码:
df2 = df.copy() # make a copy of the dataframe object df2.drop(columns = ['Date'], inplace=True) # drop the Date columns
所有列的Datatype
Date datetime64[ns] Sales float64 Budget float64 PPV float64 SOPPV float64 dtype: object
完整的Trackback:
KeyError Traceback (most recent call last) <ipython-input-81-22d4dafeb1cb> in <module> ----> 1 df2 = df.drop(columns = ['Date'], inplace=True) ~/opt/anaconda3/lib/python3.7/site-packages/pandas/core/frame.py in drop(self, labels, axis, index, columns, level, inplace, errors) 3995 level=level, 3996 inplace=inplace, -> 3997 errors=errors, 3998 ) ~/opt/anaconda3/lib/python3.7/site-packages/pandas/core/generic.py in drop(self, labels, axis, index, columns, level, inplace, errors) 3934 for axis, labels in axes.items(): 3935 if labels is not None: -> 3936 obj = obj._drop_axis(labels, axis, level=level, errors=errors) 3938 if inplace: ~/opt/anaconda3/lib/python3.7/site-packages/pandas/core/generic.py in _drop_axis(self, labels, axis, level, errors) 3968 new_axis = axis.drop(labels, level=level, errors=errors) 3969 else: -> 3970 new_axis = axis.drop(labels, errors=errors) 3971 result = self.reindex(**{axis_name: new_axis}) ~/opt/anaconda3/lib/python3.7/site-packages/pandas/core/indexes/base.py in drop(self, labels, errors) 5016 if mask.any():