Skip to content
Advertisement

Extracting Multiple Parameters from a String using Regex or Pandas

I’m working with the following DataFrame

JavaScript

Consisting of parameters (bphigh bplow weight) of type stras follows

{u'bphigh': u'120', u'bplow': u'70', u'weight': u'84.8'}

I’d like to extract these parameters and their corresponding values to columns as shown below

JavaScript

I tried using the following pandas method which hasn’t really been consistent in extracting the parameters vitals['vital'].str.extract(r"{u'bphigh':s*(w+)")

Is there a more efficient workaround in pandas or regex to this issue?

Please Advise

Advertisement

Answer

JavaScript

try:

JavaScript

Finally:

JavaScript

Now If you print out you will get your desired output

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