【发布时间】:2021-11-01 12:42:04
【问题描述】:
我有一个包含类似数据的数据框
column1
-----------
Hello (120)
234
World (22
我正在尝试删除所有部分,例如 (120) 或 (22。我写的代码是:
df['column1'] = df['column1'].str.replace(r"\((\d+)\)", "", regex = True)
df['column1'] = df['column1'].str.replace(r"\((\d+)", "", regex = True)
我的预期输出是:
column1
--------
Hello
234
World
但我得到的是:
column1
--------
Hello
World
谁能向我解释为什么 234 被删除?
【问题讨论】:
标签: python regex pandas dataframe