Revisamos de forma exhaustivamente cada una de las noticias en nuestra web con la meta de enseñarte en todo momento información veraz y certera.
Ejemplo 1: pandas que no están en la lista
>>> df
countries
0 US
1 UK
2 Germany
3 China
>>> countries
['UK','China']>>> df.countries.isin(countries)0False1True2False3True
Name: countries, dtype:bool>>> df[df.countries.isin(countries)]
countries
1 UK
3 China
>>> df[~df.countries.isin(countries)]
countries
0 US
2 Germany
Ejemplo 2: 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)0False1True2False3True
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
¡Haz clic para puntuar esta entrada!
(Votos: 0 Promedio: 0)