weixin_44562468
草地打滾的熊
采纳率33.3%
2019-05-22 09:12 阅读 387

邮编号码缺失值数据预处理

10

各位大佬,想问这个邮编号数据(邮编数据量比较大)怎么处理,可以得到以下结果,如何做字符串拆分后的中间遗失值补充呢?

原数据截图如下:
图片说明

效果图如下:
图片说明

菜鸟一枚,求各位大佬指导!!!!!

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

2条回答 默认 最新

  • 已采纳
    caozhy 从今以后生命中的每一秒都属于我爱的人 2019-05-22 09:35

    如果问题得到解决,请点我回答的左上角的采纳

    # encoding: utf-8
    
    
    list = [{'city': 'Canberra', 'zip': '0200-0299'},
            {'city': 'NT Near', 'zip': '0800-0802'}, 
            {'city': 'NT Remote', 'zip': '0803-0803'}]
    newlist = []
    for i in range(0, len(list)):
        a = int(list[i]['zip'].split('-')[0])
        b = int(list[i]['zip'].split('-')[1])
        for j in range(a, b + 1):
            newlist.append({ 'city': list[i]['city'], 'zip': str(j).zfill(4) })
    print(newlist)
    
    
    

    结果

    [{'city': 'Canberra', 'zip': '0200'}, {'city': 'Canberra', 'zip': '0201'}, {'city': 'Canberra', 'zip': '0202'}, {'city': 'Canberra', 'zip': '0203'}, {'city': 'Canberra', 'zip': '0204'}, {'city': 'Canberra', 'zip': '0205'}, {'city': 'Canberra', 'zip': '0206'}, {'city': 'Canberra', 'zip': '0207'}, {'city': 'Canberra', 'zip': '0208'}, {'city': 'Canberra', 'zip': '0209'}, {'city': 'Canberra', 'zip': '0210'}, {'city': 'Canberra', 'zip': '0211'}, {'city': 'Canberra', 'zip': '0212'}, {'city': 'Canberra', 'zip': '0213'}, {'city': 'Canberra', 'zip': '0214'}, {'city': 'Canberra', 'zip': '0215'}, {'city': 'Canberra', 'zip': '0216'}, {'city': 'Canberra', 'zip': '0217'}, {'city': 'Canberra', 'zip': '0218'}, {'city': 'Canberra', 'zip': '0219'}, {'city': 'Canberra', 'zip': '0220'}, {'city': 'Canberra', 'zip': '0221'}, {'city': 'Canberra', 'zip': '0222'}, {'city': 'Canberra', 'zip': '0223'}, {'city': 'Canberra', 'zip': '0224'}, {'city': 'Canberra', 'zip': '0225'}, {'city': 'Canberra', 'zip': '0226'}, {'city': 'Canberra', 'zip': '0227'}, {'city': 'Canberra', 'zip': '0228'}, {'city': 'Canberra', 'zip': '0229'}, {'city': 'Canberra', 'zip': '0230'}, {'city': 'Canberra', 'zip': '0231'}, {'city': 'Canberra', 'zip': '0232'}, {'city': 'Canberra', 'zip': '0233'}, {'city': 'Canberra', 'zip': '0234'}, {'city': 'Canberra', 'zip': '0235'}, {'city': 'Canberra', 'zip': '0236'}, {'city': 'Canberra', 'zip': '0237'}, {'city': 'Canberra', 'zip': '0238'}, {'city': 'Canberra', 'zip': '0239'}, {'city': 'Canberra', 'zip': '0240'}, {'city': 'Canberra', 'zip': '0241'}, {'city': 'Canberra', 'zip': '0242'}, {'city': 'Canberra', 'zip': '0243'}, {'city': 'Canberra', 'zip': '0244'}, {'city': 'Canberra', 'zip': '0245'}, {'city': 'Canberra', 'zip': '0246'}, {'city': 'Canberra', 'zip': '0247'}, {'city': 'Canberra', 'zip': '0248'}, {'city': 'Canberra', 'zip': '0249'}, {'city': 'Canberra', 'zip': '0250'}, {'city': 'Canberra', 'zip': '0251'}, {'city': 'Canberra', 'zip': '0252'}, {'city': 'Canberra', 'zip': '0253'}, {'city': 'Canberra', 'zip': '0254'}, {'city': 'Canberra', 'zip': '0255'}, {'city': 'Canberra', 'zip': '0256'}, {'city': 'Canberra', 'zip': '0257'}, {'city': 'Canberra', 'zip': '0258'}, {'city': 'Canberra', 'zip': '0259'}, {'city': 'Canberra', 'zip': '0260'}, {'city': 'Canberra', 'zip': '0261'}, {'city': 'Canberra', 'zip': '0262'}, {'city': 'Canberra', 'zip': '0263'}, {'city': 'Canberra', 'zip': '0264'}, {'city': 'Canberra', 'zip': '0265'}, {'city': 'Canberra', 'zip': '0266'}, {'city': 'Canberra', 'zip': '0267'}, {'city': 'Canberra', 'zip': '0268'}, {'city': 'Canberra', 'zip': '0269'}, {'city': 'Canberra', 'zip': '0270'}, {'city': 'Canberra', 'zip': '0271'}, {'city': 'Canberra', 'zip': '0272'}, {'city': 'Canberra', 'zip': '0273'}, {'city': 'Canberra', 'zip': '0274'}, {'city': 'Canberra', 'zip': '0275'}, {'city': 'Canberra', 'zip': '0276'}, {'city': 'Canberra', 'zip': '0277'}, {'city': 'Canberra', 'zip': '0278'}, {'city': 'Canberra', 'zip': '0279'}, {'city': 'Canberra', 'zip': '0280'}, {'city': 'Canberra', 'zip': '0281'}, {'city': 'Canberra', 'zip': '0282'}, {'city': 'Canberra', 'zip': '0283'}, {'city': 'Canberra', 'zip': '0284'}, {'city': 'Canberra', 'zip': '0285'}, {'city': 'Canberra', 'zip': '0286'}, {'city': 'Canberra', 'zip': '0287'}, {'city': 'Canberra', 'zip': '0288'}, {'city': 'Canberra', 'zip': '0289'}, {'city': 'Canberra', 'zip': '0290'}, {'city': 'Canberra', 'zip': '0291'}, {'city': 'Canberra', 'zip': '0292'}, {'city': 'Canberra', 'zip': '0293'}, {'city': 'Canberra', 'zip': '0294'}, {'city': 'Canberra', 'zip': '0295'}, {'city': 'Canberra', 'zip': '0296'}, {'city': 'Canberra', 'zip': '0297'}, {'city': 'Canberra', 'zip': '0298'}, {'city': 'Canberra', 'zip': '0299'}, {'city': 'NT Near', 'zip': '0800'}, {'city': 'NT Near', 'zip': '0801'}, {'city': 'NT Near', 'zip': '0802'}, {'city': 'NT Remote', 'zip': '0803'}]
    
    
    
    点赞 评论 复制链接分享
  • qq_39412061 吃鸡王者 2019-05-22 09:16

    你的问题说的有点模糊,但借助pandas模块,你的这些问题应该很容易解决。
    python的pandas是一个很好的数据处理模块

    点赞 评论 复制链接分享

相关推荐