我有两个名称的数据帧。数据帧较长,但我使用top3作为示例
First list name examples:
JOSEPH W. JOHN
MIMI N. ALFORD
WANG E. Li
Second list name examples:
AAMIR, DENNIS M
MAHAMMED, LINDA X
ABAD, FARLEY J
我需要在这两个dfs中提取名字,如何在一个正则表达式中提取它们
The return should be
list 1
JOSHEPH
MIMI
WANT
list 2
DNNIES
LINDA
FARLEY
我当前的代码看起来是re.search(r'(?<=,)\w+', df['name'])
,但它没有返回正确的名称。可以用Python编写两个正则表达式代码来提取这些名称吗
似乎您要在这里查找的是在之后的任何位置都没有逗号的第一个单词字符序列,而不是在之前有逗号的字符序列。因此,似乎您需要的不是积极的前瞻性断言,而是消极的前瞻性断言
尝试将以下内容用作正则表达式:
使用以下方法应用此功能:
将上述内容应用于此示例数据帧:
给出:
使用
见proof
解释
相关问题 更多 >
编程相关推荐