Home > Blockchain >  str.extract within a function
str.extract within a function

Time:12-17

I want to create a function and extract with str.extract the following string from my dataframe: 100 milliliter

But I am unable to create the function. It does work without the function.

I tried:

def extract(str):

    pattern = str.extract('\d  milliliter, str)

return (str)

How can I solve this issue?

CodePudding user response:

Try it this way. https://pandas.pydata.org/docs/reference/api/pandas.Series.str.extract.html

def extract(df):
   pattern = '(\d*\s*milliliter)'
    return df.str.extract(pattern)

extract(df['column_name'])
  • Related