I would to parse a phone field in a pandas dataframe. My phone field is named Phone and my country code field CountryCode.
It works but only when all the phones are filled:
df['Test phone'] = df.apply(lambda x:phonenumbers.parse(str(x['Phone']), str(x['CountryCode'])), axis='columns')
OK, but how to do it only if the phone, or even the country code, are filled? I tried a lot of if/else syntaxes in the lambda function, without success.
Amazing, I also tried doing it in a df.loc, it does not work neither...
Please, have you an idea?
THX
Just use an
ifandelsestatement within your lambda and test withrow.notnull().all()if all row entries are not null.I added an example from the phonenumbers project.
Output: