samedi 25 avril 2020

Extract string after pattern to unknown stop point

In a dataframe I have a column named buckets that contains rows that fit the following pattern:

{"21-45":1,"541-600":2,"46-60":2,"721-840":2,"1201-1320":1}

{"21-45":7,"481-540":10,"541-600":6,"46-60":2,"721-840":2}

{"481-540":1,"301-360":1,"<20":2,"61-120":1,"21-45":10}

{"481-540":1,"21-45":200,"721-840":1,"<20":3,"61-120":2}

I wish to extract the number that follows the pattern "21-45":

So I would be left with:

1

7

10

200

The pattern "21-45": can appear anywhere in the string and the number of digits following it vary and may end in a "," or in a "}".

The dataframe is very large, so I would like to accomplish this as parsimoniously as possible. I have no idea what the best way is to approach this problem.

Thank you.

Aucun commentaire:

Enregistrer un commentaire