Import data from Excel

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • N/A

    #1

    Import data from Excel

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

    #2
    Re: Import data from Excel

    The CSV module?

    Comment

    • N/A

      #3
      Re: Import data from Excel

      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!

      Paddy wrote:[color=blue]
      > The CSV module?
      >[/color]

      Comment

      • Dale Strickland-Clark

        #4
        Re: Import data from Excel

        Try this:

        from win32com.client import GetObject, constants

        def GetExcelData(se lf, 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(strFi lePath).Sheets( 1).UsedRange.Va lue


        N/A wrote:
        [color=blue]
        > Hi,
        > Is it possible to import data from Excel for doing numerical analysis in
        > Python? If so how? Thank u![/color]

        --
        Dale Strickland-Clark
        Riverhall Systems - www.riverhall.co.uk

        Comment

        • Mirco Wahab

          #5
          Re: Import data from Excel

          Hi,
          [color=blue]
          > Is it possible to import data from Excel for
          > doing numerical analysis in Python? If so how?[/color]

          use John Machins glamouros 'xlrd'


          form his documentation:

          import xlrd
          book = xlrd.open_workb ook("myfile.xls ")
          print "The number of worksheets is", book.nsheets
          print "Worksheet name(s):", book.sheet_name s()
          sh = book.sheet_by_i ndex(0)
          print sh.name, sh.nrows, sh.ncols
          print "Cell D30 is", sh.cell_value(r owx=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

          Comment

          Working...