Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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

import data .xls

Hi I would like to run this python script in sage (simple example): " example):

def import_xls(filename, worksheet=1):

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']

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