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'\d\d\d') def GetMuch(x): m=re.search(pattern,x) if m: return m.group(0) else: return "Not found"