I am trying to clean phone numbers using phonenumbers library. I created function to get country code & national number and store in columns 'country_code' and 'national_number'
I am trying to use apply() on dataframe which has noisy numbers. I am trying to use apply over loop due to performance gain. Below is code:
import phonenumbers
import pandas as pd
df_phone = pd.read_csv(r'D:\Code\Address-Nominatim\Address-Nominatim\Phone_Valid.csv',encoding='utf8')
df_phone['country_code'] = ''
df_phone['national_number'] = ''
df_phone['valid']=''
def phone_valid(phone):
    try:
        #print(phone['PHONE'] + " " + phone['COUNTRY'])
        x = phonenumbers.parse(phone['PHONE'],phone['COUNTRY'])
        df_phone['country_code'] = x.country_code
        df_phone['national_number'] = x.national_number
        df_phone['valid']=phonenumbers.is_possible_number(x)
    except:
        df_phone['country_code'] = "Error"
        df_phone['national_number'] = "Error"
df_phone=df_phone.apply(phone_valid,axis=1)
print(df_phone)
but dataframe df_phone only has none values.Below is sample output of df_phone
| none | none | 
|---|---|
| 1 | none | 
| 2 | none | 
Can someone tell me what mistake I am making?
Regards,
 
     
    