【发布时间】:2017-12-21 21:27:26
【问题描述】:
我有一个数组wrong_indexes_train,其中包含我想从数据框中删除的索引列表:
[0, 63, 151, 469, 1008]
要删除这些索引,我正在尝试:
df_train.drop(wrong_indexes_train)
但是,代码失败并出现错误:
ValueError: labels ['OverallQual' 'GrLivArea' 'GarageCars' 'TotalBsmtSF' 'FullBath'
'YearBuilt'] not contained in axis
这里,['OverallQual' 'GrLivArea' 'GarageCars' 'TotalBsmtSF' 'FullBath' 'YearBuilt'] 是我的数据框列的名称。
我怎样才能让数据框删除我指定的索引的整行?
【问题讨论】:
-
看看这个。 pandas.pydata.org/pandas-docs/stable/generated/… "同时指定标签和索引或列将引发 ValueError。"