Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/37.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何在新列中保存现有字符串的一部分_Python_Text_Split - Fatal编程技术网

Python 如何在新列中保存现有字符串的一部分

Python 如何在新列中保存现有字符串的一部分,python,text,split,Python,Text,Split,在数据框中,我有一列,其中包含电子邮件列表。我的经理希望我将姓名保留在新列的@之后和之前。 我尝试了以下方法: DF['newcolumn'] = DF['email'].split("@")[2].split(".")[0] 但它没有起作用。 有什么想法吗?使用以下正则表达式作为分隔符: df['email'].str.split('@|\.').str[-2] MVCE: 输出: 0 abc 1 candy 2 questinc Name: email,

在数据框中,我有一列,其中包含电子邮件列表。我的经理希望我将姓名保留在新列的
@
之后和
之前。 我尝试了以下方法:

DF['newcolumn'] = DF['email'].split("@")[2].split(".")[0]
但它没有起作用。
有什么想法吗?

使用以下正则表达式作为分隔符:

df['email'].str.split('@|\.').str[-2]
MVCE:

输出:

0         abc
1       candy
2    questinc
Name: email, dtype: object
0         abc
1       candy
2    questinc
Name: email, dtype: object