is there a more efficient way to split a column based on characters?

Viewed 21

I have a column named 'email' and I want to create a new column named 'company' that will take strings after the '@' up until the first '.' .

finaldf['email'].head(3)

0     person@company.com.br
1    woman@company.com.br
2    people@company.fr

I was able to figure out a way of doing it but it would take a couple of steps (lines of code)

1 Answers

use extract to capture the string b/w @ and period.

df['email'].str.extract(r'@(.*?)\.' )
          0
0   company
1   company
2   company
Related