hud_crosswalk.py 文件源码

python
阅读 18 收藏 0 点赞 0 评论 0

项目:us_zipcodes_congress 作者: OpenSourceActivismTech 项目源码 文件源码
def load_hud_crosswalk(fn):
    book = xlrd.open_workbook(fn)
    sheet = book.sheet_by_index(0)

    zccd = []
    for row_i in xrange(1, sheet.nrows):
        z = sheet.cell(row_i, 0).value
        stcd = sheet.cell(row_i, 1).value # formatted like STCD (FIPS, CD)
        st = stcd[:2]
        cd = stcd[2:]
        try:
            zccd.append({
                'zip': z,
                'state_fips': st,
                'state_abbr': FIPS_TO_STATE[st],
                'cd': str(int(cd)) # string conversion to drop leading zero
            })
        except Exception,e:
            msg = 'unable to convert CD for %s: %s' % (z, stcd)
            log.error(msg)
            continue
    return zccd
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号