【问题标题】:Pandas column select rows regex numbers after a specific word [closed]Pandas 列在特定单词后选择行正则表达式数字[关闭]
【发布时间】:2021-06-03 12:08:28
【问题描述】:

我正在尝试为 pandas 数据框中的以下行提取“Purchase Id: XXXXXXXX”,但我不确定要选择的正确正则表达式以 Purchase Id 开头并在数字之后结束。

我现在拥有的:

Description
"Online order Purchase Id: 14527903 Charge Id: 11111111"
"Online order Purchase Id: 90762134 Charge Id: 33345872"

想要的结果:

Description
Purchase Id: 14527903
Purchase Id: 90762134

【问题讨论】:

    标签: regex pandas


    【解决方案1】:

    试试这个来匹配Product Id: 之后的任意位数:

    df['Description'].str.extract('(Purchase Id: \d+)')
    

    或者这个匹配Product Id: 之后的8个字符:

    df['Description'].str.extract('(Purchase Id: .{8})')
    

    输出:

                           0
    0  Purchase Id: 14527903
    1  Purchase Id: 90762134
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-05-17
      • 1970-01-01
      • 1970-01-01
      • 2020-01-25
      • 2021-11-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多