Home > Back-end >  How to extract a word and its next 2 digit?
How to extract a word and its next 2 digit?

Time:11-28

I have this pandas dataframe

enter image description here

I want to extract word id and nid and its next 2 digit from log column using python. The output should be like this:

enter image description here

CodePudding user response:

Using str.extract we can try:

df["log"] = df["log"].str.extract(r'\b(n?id \d )')

Here is a regex demo.

CodePudding user response:

The above answer should work for this question. Perhaps, this link will be helpful as well and also more general.

  • Related