“pandas no en la lista” Código de respuesta

pandas no está en

df[~df.column.isin(list_name)]
D Goglia

pandas no en la lista

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

Python no en la lista

>>> 3 not in [2, 3, 4]
False
>>> 3 not in [4, 5, 6]
True
Shy Stag

nonotin 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
Smoggy Sandpiper

Respuestas similares a “pandas no en la lista”

Preguntas similares a “pandas no en la lista”

Más respuestas relacionadas con “pandas no en la lista” en Python

Explore las respuestas de código populares por idioma