str.extract within a function
Question:
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?
Answers:
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'])
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?
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'])