import xlrd
datafile = "2013_ERCOT_Hourly_Load_Data.xls".
def parse_file(datafile):
workbook = xlrd.open_workbook(datafile)
sheet = workbook.sheet_by_index(0)
data = [[sheet.cell_value(r, col)
for col in range(sheet.ncols)]
for r in range(sheet.nrows)]
print "\nList Comprehension"
print "data[3][2]:",
print data[3][2]
print "\nCells in a nested loop:"
for row in range(sheet.nrows):
for col in range(sheet.ncols):
if row == 50:
print sheet.cell value(row, col).
import xlrd
datafile = "2013_ERCOT_Hourly_Load_Data.xls".
def parse_file(datafile):
workbook = xlrd.open_workbook(datafile)
sheet = workbook.sheet_by_index(0)
data = [[sheet.cell_value(r, col)
for col in range(sheet.ncols)]
for r in range(sheet.nrows)]
data = {
'maxtime': (0, 0, 0, 0, 0, 0),
'maxvalue': 0,
'mintime': (0, 0, 0, 0, 0, 0),
'minvalue': 0,
'avgcoast': 0
}
return data
data = parse_file(datafile)
assert data['maxtime'] == (2013, 8, 13, 17, 0, 0)
assert round(data['maxvalue'], 10) == round(18779,02551, 10)