0

I'm trying to look for a string inside a dataframe column, but when I try to look for it using the 'in' operator it always returns me 'False', anyone knows why? My dataframe print showing the description is here.

  • 2
    [How to make good reproducible pandas examples](https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples) – It_is_Chris Jun 15 '21 at 19:51
  • Gabriel, Welcome to the So, its always advisable to show your data in text form with minimal data you can so others can reproduce it. – Karn Kumar Jun 15 '21 at 19:59
  • This is a duplicate, see that question – smci Jun 15 '21 at 20:20

2 Answers2

0

Try:

df["Nome"].str.contains("Karla")

If you just want to check if "Karla" is anywhere in the column:

any(df["Nome"].str.contains("Karla"))
not_speshal
  • 22,093
  • 2
  • 15
  • 30
0

There are number of ways you can get the desired data from your dataFrame:

Using str.contains ...

df1[df1['Nome'].str.contains('Karla')]

OR

df1[df1.Nome.str.contains("Karla") == True]

OR

df1[df1['Nome'].str.contains("Karla") == 0]

Using isin ...

df1[ df1['Nome'].isin(["Karla"])]

Using equal to of dataframe and other, element-wise (binary operator eq).

df1[df1.Nome == "Karla"]

OR

df1[df1['Nome'].eq("Karla")]
Karn Kumar
  • 8,518
  • 3
  • 27
  • 53