相关文章推荐
坚强的铁板烧  ·  iOS开发之UIStackView基本运用·  5 天前    · 
英俊的卡布奇诺  ·  全新荣耀MagicBook ...·  1 年前    · 
帅气的单杠  ·  sql 语句中的case when in ...·  2 年前    · 
怕考试的柿子  ·  28/10 Lunchsamtal på ...·  2 年前    · 
想发财的脸盆  ·  LocalDateTime (Joda ...·  2 年前    · 
深沉的书包  ·  如何看待镇魂街漫画最新一话中作者设置的救刘羽 ...·  2 年前    · 
Code  ›  无法删除日期列KeyError:"[' Date ']在轴中找不到开发者社区
date axis
https://cloud.tencent.com/developer/ask/sof/978690
聪明伶俐的脸盆
1 年前
首页
学习
活动
专区
工具
TVP 最新优惠活动
返回腾讯云官网
提问

问 无法删除日期列KeyError:"[' Date ']在轴中找不到

Stack Overflow用户
提问于 2020-10-17 01:23:38
EN

我有一个dataframe,它有日期、销售和预算作为列名。我想删除date列,但它给出了一个错误 KeyError: "['Date'] not found in axis"

下面是我的代码:

代码语言: javascript
复制
df2 = df.copy()   # make a copy of the dataframe object
df2.drop(columns = ['Date'], inplace=True)   # drop the Date columns

所有列的Datatype

代码语言: javascript
复制
Date                           datetime64[ns]
Sales                                 float64
Budget                                float64
PPV                                   float64
SOPPV                                 float64
dtype: object

完整的Trackback:

代码语言: javascript
复制
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():
 
推荐文章
坚强的铁板烧  ·  iOS开发之UIStackView基本运用
5 天前
英俊的卡布奇诺  ·  全新荣耀MagicBook 15锐龙版评测:AMD加持,能否再喊YES?_搜狐汽车_搜狐网
1 年前
帅气的单杠  ·  sql 语句中的case when in 与 exists - 之乎者也QAQ - 简书
2 年前
怕考试的柿子  ·  28/10 Lunchsamtal på Science Village-kontoret med Annika och Sven: möjligheter och utmaningar för LTH och Naturvetenskapliga fakul
2 年前
想发财的脸盆  ·  LocalDateTime (Joda time 1.6 API)
2 年前
深沉的书包  ·  如何看待镇魂街漫画最新一话中作者设置的救刘羽禅还是红莲的选择题?你会投谁一票? - 知乎
2 年前
今天看啥   ·   Py中国   ·   codingpro   ·   小百科   ·   link之家   ·   卧龙AI搜索
删除内容请联系邮箱 2879853325@qq.com
Code - 代码工具平台
© 2024 ~ 沪ICP备11025650号