Filter DataFrame Rows Using In and Not In Equivilant

Python

 1|  sex = ['male']
 2|  
 3|  # filter dataframe to include only male values in the sex column
 4|  males = df[df['Sex'].isin(sex)]
 5|  
 6|  # filter dataframe to include only values that are not male in 
 7|  # the sex column
 8|  females = df[~df['Sex'].isin(sex)]
Did you find this snippet useful?

Sign up for free to to add this to your code library