【问题标题】:Dataframe _ Replace / Python数据框_替换/ Python
【发布时间】:2020-10-23 01:22:08
【问题描述】:

我正在尝试删除数据框中括号中的字符。

我在下面尝试过,但没有成功。

df['contents'] = df['contents'].str.replace(pat='([.,!?"\':;~()[]]+\[a-zA-Z0-9.+-]+[.,!?"\':;~()[]])', repl ='', regex = False)

例如(在数据框中) [abc]定义 => 定义

感谢您的洞察力。

【问题讨论】:

  • 是否有多组方括号?您能否澄清一下,方括号[] 或括号()

标签: python regex pandas string dataframe


【解决方案1】:

试试这个:

df['contents'] = df['contents'].str.replace(pat=r's/\([^)]*\)//', repl ='', regex = True)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-05-15
    • 1970-01-01
    • 2017-08-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多