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

Find Rows Where Column Value Contain in a String

Example:

data='findme, ok'
df = pd.DataFrame([x.split(',') for x in data.split('\n')])
df.columns = ['keyword', 'result']
keywords = df['keyword'].tolist()
test1='maybe you canfindme'.lower()

How can I convert the below syntax to dataframe syntax?

for keyword in df['keyword'].tolist():
    if keyword in test1:
        print(keyword)

Of course this is wrong, but I am looking for something like this:

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

filter_result = df[df['keyword'] in test1]

>Solution :

One way to do that is to use the map method.

See Map method documentation

In your case:

df[df['keyword'].map(lambda k: k in test1)==True]
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