0

I am struggling to drop rows that do not contain certain data. For example, I want my dataset to only predict between 'Male' and 'Female' so I need to drop everything with the 'Gender' column that is not equal to those two choices. How would I go about doing this?

I've tried:

df.drop(df['GENDER'] != 'Male' & 'Female')

I honestly have tried more code that I can type out so any help would be great. All of the pandas documentation I have read only shows how to remove certain values but not how to remove everything but certain values.

Thanks in advance!

2 Answers2

0

Here you go

df = df[df.GENDER.isin(['Male',"Female"])]
sayan dasgupta
  • 1,084
  • 6
  • 15
0
df = df[~df['GENDER'].isin(['Male',"Female"])]
ZAVERI SIR
  • 317
  • 4
  • 14