1>>> df
2 countries
30 US
41 UK
52 Germany
63 China
7>>> countries
8['UK', 'China']
9>>> df.countries.isin(countries)
100 False
111 True
122 False
133 True
14Name: countries, dtype: bool
15>>> df[df.countries.isin(countries)]
16 countries
171 UK
183 China
19>>> df[~df.countries.isin(countries)]
20 countries
210 US
222 Germany
1import pandas as pd
2
3>>> df
4 country
50 US
61 UK
72 Germany
83 China
9>>> countries_to_keep
10['UK', 'China']
11>>> df.country.isin(countries_to_keep)
120 False
131 True
142 False
153 True
16Name: country, dtype: bool
17>>> df[df.country.isin(countries_to_keep)]
18 country
191 UK
203 China
21>>> df[~df.country.isin(countries_to_keep)]
22 country
230 US
242 Germany