import data .xls
Hi I would like to run this python script in sage (simple example):
def import_xls(filename, worksheet=1):
import xlrd
book = xlrd.open_workbook(filename)
sh = book.sheet_by_index(worksheet - 1)
data = []
for i in range(sh.ncols):
data.append(sh.col_values(i))
print 'Worksheet Names: %s; Rows: %s; Columns: %s'%(sh.name, sh.nrows, sh.ncols)
return data
def export_xls(data, filename):
import xlwt
wb = xlwt.Workbook()
ws = wb.add_sheet('Sheet1')
for i in range(len(data)):
for k in range(len(data[i])):
ws.write(i,k,str(data[i][k]))
return wb.save(filename)
from cvxopt import matrix
from cvxopt import solvers
from numpy import array
from numpy import zeros
A = import_xls('sample.xls', worksheet=1)
b = import_xls('sample.xls', worksheet=2)
c = import_xls('sample.xls', worksheet=3)
# linear programming model
A = matrix(A)
b = matrix(b)
c = matrix(c)
sol=solvers.lp(c,A,b)
print sol['x']
x = sol['x']
But it returns the following error: ImportError: No module named xlrd Can you help me? Thanks a lot