How to filter lines that have a certain string?

Asked

Viewed 1,046 times

1

I know that the command dados[dados.Value == 'disease'] only the lines where the value of the column "Value" is exactly equal to the string "disease", but I need to select all the rows in the column "Value" that have the word "disease" (disease) in the middle of the character set. It’s like I’m gonna make a select * from df where value like "%disease%". You can do this in Pandas ?

The expected result is something like:

                                     Entity          Relation                                 Value

2653297                         candy:heart  theriskofdisease  concept:disease:non_insulin_diabetes
2474203  physiologicalcondition:n2_diabetes        synonymfor  concept:disease:non_insulin_diabetes

1 answer

5

The solution is to use the function .contains.

dados[dados.Value.str.contains("disease", regex=False)]

It is worth noting that this function assumes that the string passed is a regular expression, that is, it has the parameter regex=True as a standard.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.