【问题标题】:Iterate over pandas dataframe column, search for parentheses and delete them (and everything inside of it)遍历 pandas dataframe 列,搜索括号并删除它们(以及其中的所有内容)
【发布时间】:2023-02-16 22:52:26
【问题描述】:

我想实现以下目标。我有一个包含“电子邮件”列的熊猫数据框。我想遍历此列中的行并在每个单元格中搜索括号。除此之外,我还想删除括号并删除其中的所有内容,例如:

"Steen, A.K. (Test) de" 应该是 "Steen, A.K. de" “姓氏,T.(测试)”应为“姓氏,T”。

谁能帮我这个?

在网上搜索了很多。我仍在学习 Python 编程,但我发现它非常困难。

【问题讨论】:

    标签: python pandas parentheses


    【解决方案1】:

    使用str.replace

    df['col_name'] = df['col_name'].str.replace(r's*(.*)s*', '', regex=True)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-01-27
      • 1970-01-01
      • 1970-01-01
      • 2014-10-18
      • 2016-08-18
      • 2022-11-03
      • 2022-11-01
      • 2011-10-23
      相关资源
      最近更新 更多