def read_excel(fname, header=None):
"""Read excel into dict.
Args:
fname: name of excel file
header: The finland files does not have a header
Output:
dictionary containing the data
"""
xls = ExcelFile(fname)
if header:
parse_cols = [1]
else:
parse_cols = None
df = xls.parse(xls.sheet_names[0], skiprows=1,
parse_cols=parse_cols)
# Fix keys
temp = df.to_dict()
for key in temp:
new_key = key.replace(" - ", "_")
temp[new_key] = temp.pop(key)
# Stupid hack for Finland
if header:
temp[header] = temp.pop(temp.keys()[0])
return temp
评论列表
文章目录