I have this pandas dataframe
I want to extract word id and nid and its next 2 digit from log column using python. The output should be like this:
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.