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

How to search for a term in a Dataframe and return Yes or no

I have written that extracts a data from a API.That data is called cadata. I wanted to check whether a particular text contains in this column – cadata['Source'] This column is of 2000 Rows. So what i wanted to do is that tell whether that text contains in that column row or not. If yes return yes if no then return no

>Solution :

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

I assume that you want add a column to the dataframe, containing the return for each row.

Use contains from string functions to look for a text fragment in each row. This return either True False. With replace you can map the result to yes or no.

cdata['contains_text'] = cdata['source'].str.contains(text_to_check)

# map True to 'yes' and False to 'no'
cdata['contains_text'] = cdata['contains_text'].replace({True: 'yes', False: 'no})
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