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 make a dataframe by changing condition on url?

I have a dataframe, which contains many urls, is there a way i can make whenever it finds a specific url "https://abs.twimg.com/sticky/default_profile_images/default_profile_normal.png" it gives a value False, else true?

My dataframe:

Expected:

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

surname value
First True
Second False
Third True
Fourth False

>Solution :

You can use contains which creates a boolean mask. By assigning it to df['value'] you assign it to a new column, which gives you the desired result. This is even easier than creating a lambda function for it.

df['value'] = df.image_url.str.contains("https://abs.twimg.com/sticky/default_profile_images/default_profile_normal.png")
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