通过手机号解析出手机号归属地的省、市、运营商、邮编、区号

首先需要pip安装 phone 第三方模块

通过 phone.Phone.find() 函数解析

from phone import Phone

def get_mobile_location(phoneNum):
    """    
    """
    info = Phone().find(phoneNum)
    try:
        province = info['province']
        city = info['city']
        zip_code = info['zip_code']
        area_code = info['area_code']
        phone_type = info['phone_type']
        return [province, city, phone_type, zip_code, area_code]
    except:
        return ['', '', '', '', '']

单条解析

get_mobile_location('手机号')

通过手机号解析出手机号归属地的省、市、运营商、邮编、区号_第1张图片

 批量解析

df_mobile[['province', 'city', 'phone_type', 'zip_code', 'area_code']] = df_mobile['mobile'].apply(lambda mobile: pd.Series(get_mobile_location(mobile)))

通过手机号解析出手机号归属地的省、市、运营商、邮编、区号_第2张图片

你可能感兴趣的:(金融风控,Python,数据分析)