Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Drop rows by index from dataframe

I have an array wrong_indexes_train which contains a list of indexes that I would like to remove from a dataframe:

[0, 63, 151, 469, 1008]

To remove these indexes, I am trying this:

df_train.drop(wrong_indexes_train)

However, the code fails with the error:

ValueError: labels ['OverallQual' 'GrLivArea' 'GarageCars' 'TotalBsmtSF' 'FullBath'
 'YearBuilt'] not contained in axis

Here, ['OverallQual' 'GrLivArea' 'GarageCars' 'TotalBsmtSF' 'FullBath' 'YearBuilt'] are the names of my dataframe's columns.

How could I just make the dataframe drop the entire rows of the indices that I specified?

like image 899
octavian Avatar asked Dec 21 '17 21:12

octavian


1 Answers

Change it to

df_train.drop(wrong_indexes_train,axis=1)
like image 110
Gabriel A Avatar answered Oct 22 '22 17:10

Gabriel A