Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Filter by string column as a substring of another string

I am trying to filter a dataframe by a string column. I would like the filter to return all rows where this string column is a substring of another string. Any searching I do for this problem leads to results about the converse – filtering a dataframe where a string columns contains a substring.

In other words, what I am attempting to achieve is:

df[df["string_column"] in "some_string"]

or

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

df[df["string_column"].str.is_substring_of("some_string")]

not

df[df["string_column"].str.contains("some_string")]

>Solution :

df[df["string_column"].apply(lambda x: x in "some_string")]
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading