【问题标题】:IndexError: only integers, slices (`:`), ellipsis (`...`), numpy.newaxis (`None`) and integer or boolean arrays are valid indices I need drop columnsIndexError: 只有整数、切片 (`:`)、省略号 (`...`)、numpy.newaxis (`None`) 和整数或布尔数组是有效的索引我需要删除列
【发布时间】:2022-06-11 00:09:36
【问题描述】:

代码:

df1 = ndata.drop(ndata.columns[to_drop], axis=1)
print(ndata.head())

错误:

索引错误

回溯(最近一次通话最后一次)
在 ()
----> 1 df1 = ndata.drop(ndata.columns[to_drop],axis=1)
2 df1=int(df1)
3 打印(ndata.head())

/usr/local/lib/python3.7/dist-packages/pandas/core/indexes/base.py in getitem(self, key)
第4614章 4615
-> 4616 结果 = getitem(key)
4617 如果不是 is_scalar(结果):
4618 # 错误:“ndim”的参数 1 具有不兼容的类型“Union[ExtensionArray,

IndexError:只有整数、切片 (:)、省略号 (...)、numpy.newaxis (None) 和整数或布尔数组是有效的索引

这里我需要使用 to_Drop 变量从主数据框中删除列

【问题讨论】:

  • 试试这个:df1 = ndata.drop(['name_col' , 'name_col2'], axis=1)

标签: machine-learning data-science


猜你喜欢
  • 2017-12-08
  • 2019-03-13
  • 2017-11-24
  • 2019-12-12
  • 1970-01-01
  • 2021-09-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多