gpt4 book ai didi

python - 从数据框中按索引删除行

转载 作者:行者123 更新时间:2023-12-02 05:14:04 25 4
gpt4 key购买 nike

我有一个数组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'] 是我的数据框列的名称。

如何让数据框删除我指定的索引的整行?

最佳答案

更改为

df_train.drop(wrong_indexes_train,axis=1)

关于python - 从数据框中按索引删除行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47932937/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com