Home > Software engineering >  Pandas.str.extract multiple condition
Pandas.str.extract multiple condition

Time:01-06

how to put multiple reg expression in extract , i get syntax error.

enter image description here

I try so many things but doesn't help . please help and thanks.

CodePudding user response:

The raw-string r must be connected with the regex string, without whitespaces. That's why you are getting the invalid syntax error.

You should use

.str.extract(r'([aeiou].)|(\d{4})')

CodePudding user response:

you could use this method as well:

import re
x = ['aadsadasd','ewdwwe']
df = pd.DataFrame(x)
df['m'],i = '',0
a = [m for m in df[0]]
for x in a:
    print(x)
    df['m'][i] = re.findall(r'([aeiou])|(\d{4})',x)
    i = 1
  •  Tags:  
  • Related