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

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

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

效果图如下:
图片说明

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

2个回答

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

# 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'}]


weixin_44562468
草地打滾的熊 回复操作员马善福(贵阳专业挖机):跪求大佬可以给一个整体流程:从数据表导入到生成结果的操作。$_$
11 个月之前 回复
weixin_44562468
草地打滾的熊 回复操作员马善福(贵阳专业挖机): 好的,我试试
11 个月之前 回复
caozhy
每个人都有一个梦才不会孤单的说话就有天堂 也可以用xlrd,如果你是写一次性的程序,这个略微麻烦一点 https://www.cnblogs.com/ivanpan/p/7300335.html
11 个月之前 回复
caozhy
每个人都有一个梦才不会孤单的说话就有天堂 回复草地打滾的熊: 可以excel另存为csv,用pandas的readcsv函数读取
11 个月之前 回复
weixin_44562468
草地打滾的熊 大佬你好,你是如何把导入的excel原文件,储存成列表字典型的目标数据格式呢?
11 个月之前 回复

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

weixin_44562468
草地打滾的熊 你好,我这里用pandas是可以取到两端的值,而对于邮编中间的缺失值,要怎么补充呢?比如0804-0821中间的邮编0805-0820,做成效果图那样。
11 个月之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问