pandas使用正则表达式对某列数字进行提取

python对正则表达式进行处理流程:

1.引入re模块

2.根据要求编写正则表达式

3.使用compile进行编译

4.match、search、find等函数进行匹配。

import re
data_Month["价格"]=data_Month.apply(lambda x:GetMuch(x["产品"]) ,axis = 1)
pattern = re.compile(r'ddd')
def GetMuch(x):
    m=re.search(pattern,x)
    if m:
        return  m.group(0)
    else:
        return "Not found"
原文地址:https://www.cnblogs.com/wangzhenghua/p/13691255.html