【问题标题】:Pandas extract between multiple Start words and multiple stop words熊猫在多个起始词和多个停止词之间提取
【发布时间】:2021-07-27 08:37:08
【问题描述】:

Pandas DataFrame extract between one START word and multiple STOP words 开始,是否也可以将解决方案扩展到多个起始词? 示例不应按字面意思理解:

df 
   
0   start_word1  text1 end_word1
1   start_word2  text2 end_word2

预期输出

df 
   
0   text1 
1   text2 

【问题讨论】:

    标签: python python-3.x pandas python-re


    【解决方案1】:

    您可以使用non-capturing groups 定义开始/停止词的替代方案:

    df['COLUMN_NAME'].str.extract('(?:start_word1|start_word2)\s+(.*)\s+(?:end_word1|end_word2)')
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-10-12
      • 2021-05-08
      • 1970-01-01
      • 1970-01-01
      • 2020-12-27
      • 1970-01-01
      • 1970-01-01
      • 2018-12-31
      相关资源
      最近更新 更多