Skip to content
Advertisement

Repeat pattern using python regex

Well, I’m cleaning a dataset, using Pandas. I have a column called “Country”, where different rows could have numbers or other information into parenthesis and I have to remove them, for example: Australia1, Perú (country), 3Costa Rica, etc. To do this, I’m getting the column and I make a mapping over it.

JavaScript

But I have a problem with this regex, I cannot match names as “United States of America”, because it only takes “United “. How can I repeat unlimited the pattern of the fisrt group to match the whole name?
Thanks!

Advertisement

Answer

In this situation, I will clean the data step by step.

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement