Import data from Excel

N

N/A

Hi,
Is it possible to import data from Excel for doing numerical analysis in
Python? If so how? Thank u!
 
N

N/A

sorry, can you say it more clearly?
In Matlab, I can easily import data from Excel just simply use 'xlsread'
command. How to do that in Python environment? thank u!
 
D

Dale Strickland-Clark

Try this:

from win32com.client import GetObject, constants

def GetExcelData(self, strFilePath):
""" Extract the data from the Excel sheet.
Returns tuple of tuples representing the rows and cells."""
# The following line extracts
# all the data from sheet 1 of the spreadsheet
return GetObject(strFilePath).Sheets(1).UsedRange.Value
 
M

Mirco Wahab

Hi,
Is it possible to import data from Excel for
doing numerical analysis in Python? If so how?

use John Machins glamouros 'xlrd'
http://www.lexicon.net/sjmachin/xlrd.htm

form his documentation:

import xlrd
book = xlrd.open_workbook("myfile.xls")
print "The number of worksheets is", book.nsheets
print "Worksheet name(s):", book.sheet_names()
sh = book.sheet_by_index(0)
print sh.name, sh.nrows, sh.ncols
print "Cell D30 is", sh.cell_value(rowx=29, colx=3)
for rx in range(sh.nrows):
print sh.row(rx)

This module is (imho) quite useful. No
need for installed Windows or Office.

Regards

Mirco
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,294
Messages
2,571,511
Members
48,213
Latest member
DonnellTol

Latest Threads

Top