Search code examples
pythondatasetdelete-row

KeyError in deleting rows in a dataset with drop (python)


i want to delete rows with the "white" value type: the problem I'm getting is with drop and the row

for row in df_red['type']:
if(row =='white'):
    df_red.drop(row,axis=0,inplace=True)

Solution

  • You can use the pandas query function for selecting rows where type isn't white

    df_red = df_red.query('type!= "white"')