Opening and reading an excel .xlsx file in python

后端 未结 3 512
星月不相逢
星月不相逢 2021-01-03 00:15

I\'m trying to open an excel .xlsx file with python but am unable to find a way to do it, I\'ve tried using pandas but it\'s wanting to use a library called NumPy I\'ve trie

3条回答
  •  既然无缘
    2021-01-03 00:37

    Maybe you could export your .xlsx to a .csv file?

    Then you could try:

    import csv
    with open('file.csv','rb') as file:
        contents = csv.reader(file)
        [x for x in contents]
    

    This may be useful: http://docs.python.org/2/library/csv.html#csv.reader

    Hope that helps!

    EDIT:

    If you want to locate a spectific cell, such as F13, you could make a nested list like a matrix and them refer to each element:

    import csv
    with open('file.csv','rb') as file:
        contents = csv.reader(file)
        matrix = list()
        for row in contents:
            matrix.append(row)
    

    And then access F13 with matrix[5][12].

    P.S.: I did not test this. If "row" is a list with each cell as an element, you keep appending all lines to the matrix, so the first index is row number and the second is the column number.

提交回复
热议问题