将电话号码功能应用于系列
Applying Phonenumbers function to Series
我有以下代码解析一些文本并输出国际 phone 号码。
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
即当识别出两个 phone 数字时,它们将输出为逗号分隔值
# 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)
我有以下代码解析一些文本并输出国际 phone 号码。
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
即当识别出两个 phone 数字时,它们将输出为逗号分隔值
# 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)