簡體   English   中英

將電話號碼功能應用於系列

[英]Applying Phonenumbers function to Series

我有以下代碼,通過一些文本進行解析並輸出國際電話號碼。

IN[]:
import phonenumbers
text = "02-2947145 Call this +639154764945"

for match in phonenumbers.PhoneNumberMatcher(text, "PH"):
    print(phonenumbers.format_number(match.number, phonenumbers.PhoneNumberFormat.E164))

OUT[]:
+6322947145
+639154764945

我需要將此代碼應用於數據框內的一系列數據,例如

ID    Phone
1     +639154764945
2     00639154764945
3     09154764945 or call this +639154764944
4     00639154764945

我想這些輸出這樣

ID    Phone_clean
1     +639154764945
2     +639154764945
3     +639154764945, +639154764944
4     +639154764945

即,當識別出兩個電話號碼時,它們將以逗號分隔的值輸出

#  Defining a function to convert phone numbers to International format
def phone_cleaner(fc_lead_phone):
    for match in phonenumbers.PhoneNumberMatcher(fc_lead_phone,"PH"):
        return phonenumbers.format_number(match.number, phonenumbers.PhoneNumberFormat.E164)

leads['phone_one_clean'] = leads['phone_one'].apply(phone_cleaner)    

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM