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:
surname | value |
---|---|
First | True |
Second | False |
Third | True |
Fourth | False |
CodePudding user response:
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")
CodePudding user response:
Can you try the following:
url_pattern = "https://abs.twimg.com/sticky/default_profile_images/default_profile_normal.png"
df['value'] = df['image_url'].apply(lambda x: True if x == url_pattern else False)