Henrique Coura
Henrique Coura

Reputation: 852

Extract two url occurrences in a pandas field of strings

So given this example Series

s = pd.Series(["Redirecting (301) to <GET http://www.vix.com/pt/mulher> from <GET http://www.vix.com/pt/bolsademulher>'",
               "Redirecting (307) to <GET https://twibbon.com/> from <GET http://twibbon.com/>'"])

I am able to extract the first url like this:

s.str.extract('(https?://[^>]+)', expand=True)

But I would like to extract both urls, each to a different column.

Upvotes: 1

Views: 248

Answers (1)

Kyle
Kyle

Reputation: 2894

s.str.extractall('(https?://[^>]+)').unstack()

Upvotes: 2

Related Questions