【问题标题】:Python remove sections of string based on fluid start/end pointPython根据流体开始/结束点删除字符串部分
【发布时间】:2021-08-14 17:01:34
【问题描述】:

我正在使用 pandas 数据框,如果可能的话,我希望得到以下解决方案。

我有字符串“A”,并希望根据识别起点和终点对其进行修改以删除字符串“B”中显示的某些部分(数据包含许多行,删除的项目可以出现在字符串)

一个-

Sunshine <long swing-people="11-22-33">#Drive</long>, A frog is any member of a diverse and largely   <long swing-people="11-22-33">#Thru</long> carnivorous group of short-bodied, tailless amphibians.

B-

Sunshine #Drive, A frog is any member of a diverse and largely #Thru carnivorous group of short-bodied, tailless amphibians.

【问题讨论】:

    标签: python pandas string replace


    【解决方案1】:

    这应该是评论,但我还不能评论...

    起点/终点是否已经确定?

    在这些示例中,起点似乎是#,终点是单个.,总是这样吗? 如果是这样,这应该可以工作(cf pandas'documentation):

    df[column_name].str.replace(r"#.*(?=\.)", "", regex=True)
    

    编辑:我(再次)在str.replace 和pandas.Series.str.replace 之间混淆了...修复了代码 sn-p

    【讨论】:

      猜你喜欢
      • 2022-01-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-14
      • 1970-01-01
      • 2018-12-05
      • 1970-01-01
      • 2012-02-11
      相关资源
      最近更新 更多