【问题标题】:Validation phonenumbers column python pandas with phonenumbers library验证 phonenumbers 列 python pandas 与 phonenumbers 库
【发布时间】:2021-07-10 00:39:05
【问题描述】:

我想使用 phonenumbers 库从我的数据框中检查多个电话号码 https://pypi.org/project/phonenumbers/

我想验证电话号码,最终我想知道该号码来自哪个国家/地区。比如:

contact phoneNumber phoneCheck phoneCountry
1 31650868016 True Netherlands
2 447986123456 True United Kingdom
3 55677 False

我使用了这个解决方案:https://stackoverflow.com/a/56782746 我做了一个国家专栏。

但我想使用 phonenumbers.is_valid_number() 函数,最终使用 geocoder.description_for_number() 函数。

df['phone_number_clean'] = df.apply(lambda x: 
                              phonenumbers.is_valid_number(phonenumbers.is_valid_number(str(x.phoneNumber), 
                                                 str(x.Country)), 
                              axis='columns'))

错误:AttributeError:“系列”对象没有属性“电话号码”

【问题讨论】:

    标签: python pandas libphonenumber


    【解决方案1】:

    导致此错误的具体问题是axis 之后而不是之前的括号错误:

    df['phone_number_clean'] = df.apply(lambda x: phonenumbers.is_valid_number(phonenumbers.is_valid_number(str(x.phoneNumber), str(x.phoneCountry))),轴='列')

    我认为以下是您正在寻找的更多内容:

    df['phone_number_clean'] = df.apply(lambda x: phonenumbers.is_valid_number(phonenumbers.parse("+"+str(x.phoneNumber), None)), axis=1)

    我使用 None 作为占位符,因为您的 DataFrame 中没有国家/地区代码。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-10-04
      相关资源
      最近更新 更多