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

Validating urls in a pandas dataframe column using validators module

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

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

['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

>Solution :

You can do that with the following

results = [x for x in df["url"].values if validators.url(x) == 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