How to check if row exists inside row in column

What I want to do, I realized, would look like this:

(t in df[self.target]).any()

But I get:

AttributeError: 'bool' object has no attribute 'any'
+4
source share
2 answers

You can use the Pandas methods str( docs ).

df[self.target].str.contains(t).any()
+4
source

I assume this is a pandas DataFrame. try it

(df[self.target] == t).any()

EDIT:

any((t in k for k in df[self.target]))
0
source

Source: https://habr.com/ru/post/1650236/


All Articles