0
'(ep1270399)\nname=stet, johannes cornelis p/a ballast nedam infra b.v., p.o. box 1526 , city=3430 bm  nieuwegein , country=nl \n\nname=bos, wilhelmus johannes p/a ballast nedam infra b.v., p.o. box 1526 , city=3430 bm  nieuwegein , country=nl \n'

I have a pandas dataframe and I would like to extract the name which is always after a certain keyword \nname=. Hence, I would like to get 'stet' and 'bos' and put it in an array.

1
  • can you post a sample dataframe Commented Dec 30, 2019 at 6:10

1 Answer 1

1

Assuming that the string you provided is a string (Based on the quotations);

import re

string = '(ep1270399)\nname=stet, johannes cornelis p/a ballast nedam infra b.v., p.o. box 1526 , city=3430 bm nieuwegein , country=nl \n\nname=bos, wilhelmus johannes p/a ballast nedam infra b.v., p.o. box 1526 , city=3430 bm nieuwegein , country=nl \n'

split = re.split(' |=|,|\n', string)
result = [split[idx + 1] for idx, value in enumerate(split) if value == 'name']

result

['stet', 'bos']

This allows you to extract all values after \nname=. However if this data is stored differently, you will need to display so in your question so I can better tailor an answer for you!

You should be able to transfer the regex across to any format however.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.