nick34992
6/25/2017 - 2:21 PM

Python: xlrd, .xlsx, pprint

Python: xlrd, .xlsx, pprint

import xlrd

book = xlrd.open_workbook("data/SOWC-2016_all-tables_261.xlsx")
sheet = book.sheet_by_name("Table 9")
data = {}

for i in xrange(7, sheet.nrows):
    row = sheet.row_values(i)
    country = row[1]
    data[country] = {
        'child_labor': {
            'total': [row[2], row[3]],
            'male': [row[4], row[5]],
            'female': [row[6], row[7]]
        },
        'child_marriage': {
            'married_by_15': [row[8], row[9]],
            'married_by_18': [row[10], row[11]]
        }
    }
    if country == "Zimbabwe":
        break

import pprint
pprint.pprint(data)