Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

isnotin python

import pandas as pd

>>> df
  country
0        US
1        UK
2   Germany
3     China
>>> countries_to_keep
['UK', 'China']
>>> df.country.isin(countries_to_keep)
0    False
1     True
2    False
3     True
Name: country, dtype: bool
>>> df[df.country.isin(countries_to_keep)]
  country
1        UK
3     China
>>> df[~df.country.isin(countries_to_keep)]
  country
0        US
2   Germany
Comment

PREVIOUS NEXT
Code Example
Python :: python for enumerate 
Python :: how to write a comment in python 
Python :: how to move the last column to the first column in pandas 
Python :: pandas value in series 
Python :: boxplot python 
Python :: how to union value without the same value in numpy 
Python :: Drop multiple columns with their index 
Python :: add gaussian noise python 
Python :: create a database in python 
Python :: login url 
Python :: sort values within groups pandas dataframe 
Python :: list of dict to dict python 
Python :: run python script on remote server 
Python :: var_dump in python 
Python :: list all files in python 
Python :: close a file python 
Python :: python find index of closest value in list 
Python :: extract value from tensor pytorch 
Python :: if key in dictionary python 
Python :: VALUE ERROR EXCEPTION 
Python :: how to print a newline in python 
Python :: docstrings in python 
Python :: binary list to decimal 
Python :: python printing hello world 
Python :: hyperparameters 
Python :: how to get session value in django template 
Python :: fillna spark dataframe 
Python :: return function python 
Python :: change value in nested dictionary python 
Python :: concatenate list 
ADD CONTENT
Topic
Content
Source link
Name
6+3 =