【问题标题】:Extract all contents inside brackets (including the brackets) in a data frame column [duplicate]提取数据框列中括号内的所有内容(包括括号)[重复]
【发布时间】:2022-01-18 17:31:51
【问题描述】:

我在DataFrame 中有这列数据(这里只是在CSV 文件中显示):

我要做的是提取括号内的所有数据并包括括号,因此每一行看起来像这样

[GO:0005524],[GO:0000287],[GO:0004709],[GO:0004674],etc...

这是我到目前为止的代码,但我总是以一个空白列结束:

df['go_molecular_function'] = df['go_molecular_function'].str.extract(r"\((A-Za-z+)\)", expand=False)

【问题讨论】:

标签: python regex pandas


【解决方案1】:

我发现我使用了这个代码

df['go_molecular_function'] = df['go_molecular_function'].str.findall(r"(?<=\[)([^]]+)(?=\])")

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-10-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-04
    • 1970-01-01
    相关资源
    最近更新 更多