def __init__(self, sheet): self._sheet = sheet def get_data(): for i in range(self._sheet.nrows): row = self._sheet.row(i) r = map(lambda x : x.value, row) yield r self._data = ftypes.list(*get_data())
def parse_file(fp, transforms): reader = csv.reader(fp) headers = reader.next() rows = [headers] for row in reader: values = [transforms[k](v) for (k, v) in zip(headers, row)] rows.append(values) return ftypes.list(*rows)
def extract_years(data, key, blank="-", years=years): newdata = ftypes.list() for year in years: added = False for item in data: if item['Year'] == str(year) and not added: added = True newdata.append(item[key]) if not added: newdata.append(blank) return newdata
def __init__(self, file_path, sheet_name): self.workbook = xlrd.open_workbook(file_path) self.sheet = self.workbook.sheet_by_name(sheet_name) self.data = ftypes.list(*self._load_data())
def pad(length, pad, oldlist): newlist = ftypes.list([pad] * length) for i in range(0, len(oldlist)): newlist[i] = oldlist[i] return newlist