I have a dataframe containing urls which can has to be validated and obtain the resultant valid as list. The module used for validation of url is validators
module.
Dataframe is like
pd.DataFrame({'url':['https://quotes.toscrape.com/','https://www.nashvillesymphony.org/','www.google.com']})
Output Required
['https://quotes.toscrape.com/','https://www.nashvillesymphony.org/']
Tried data.loc[lambda data: validators.url(data.url) == True]
but getting an error TypeError: expected string or bytes-like object
CodePudding user response:
You can do that with the following
results = [x for x in df["url"].values if validators.url(x) == True]
CodePudding user response:
You can use:
import validators
mask1 = df["url"].apply(validators.url) == True
df[mask1]
Output
url | |
---|---|
0 | https://quotes.toscrape.com/ |
1 | https://www.nashvillesymphony.org/ |