2024-04-28 09:10:36 发布
网友
我正在尝试提取包含文本数据的列中的值,如下所示:
create date:1953/01/01 | first author:REAGAN RL
如何从列中提取作者姓名并存储在新列中。 我尝试了以下方法:
df.str.extract("first author:(.*?)")
及
authorname=df['EntrezUID'].apply(lambda x:x.split("first author:"))。第二个成功了
authorname=df['EntrezUID'].apply(lambda x:x.split("first author:"))
如何使用正则表达式实现类似的功能
你可以做:
## sample data df = pd.DataFrame({'dd':['create date:1953/01/01 | first author:REAGAN RL','create date:1953/01/01 | first author:MEGAN RL']}) ## output df['names'] = df['dd'].str.extract(r'author\:(.*)') print(df) dd names 0 create date:1953/01/01 | first author:REAGAN RL REAGAN RL 1 create date:1953/01/01 | first author:MEGAN RL MEGAN RL
你可以做:
相关问题 更多 >
编程相关推荐