我有以下代码解析一些文本并输出国际电话号码。
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
即。当识别出两个电话号码时,它们将以逗号分隔值
输出答案 0 :(得分:0)
# 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)