【问题标题】:How to extract a word and its next 2 digit?如何提取一个单词及其下一个 2 位数字?
【发布时间】:2022-01-05 01:49:14
【问题描述】:

我有这个熊猫数据框

enter image description here

我想使用 python 从日志列中提取单词 id 和 nid 及其下一个 2 位数字。输出应该是这样的:

enter image description here

【问题讨论】:

    标签: python python-3.x pandas dataframe


    【解决方案1】:

    使用str.extract我们可以试试:

    df["log"] = df["log"].str.extract(r'\b(n?id \d+)')
    

    这是regex demo

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-07
      • 1970-01-01
      • 1970-01-01
      • 2018-04-05
      • 1970-01-01
      • 2019-05-17
      相关资源
      最近更新 更多