Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to open xlsx file with python 3

Tags:

I have an xlsx file with 1 sheet. I am trying to open it using python 3 (xlrd lib), but I get an empty file!

I use this code:

file_errors_location = "C:\\Users\\atheelm\\Documents\\python excel mission\\errors1.xlsx" workbook_errors = xlrd.open_workbook(file_errors_location) 

and I have no errors, but when I type:

workbook_errors.nsheets 

I get "0", even the file has some sheets... when I type:

workbook_errors  

I get:

xlrd.book.Book object at 0x2.. 

any help? thanks

like image 999
Atheel Massalha Avatar asked May 25 '16 10:05

Atheel Massalha


People also ask

How do I read an XLSX file from Excel in Python?

Method #1: OpenPyXL OpenPyXL is a Python library created for reading and writing Excel 2010 xlsx/xlsm/xltx/xltm files. It can read both the . xlsx and . xlsm file formats, which includes support for charts, graphs, and other data visualizations.


1 Answers

You can use Pandas pandas.read_excel just like pandas.read_csv:

import pandas as pd file_errors_location = 'C:\\Users\\atheelm\\Documents\\python excel mission\\errors1.xlsx' df = pd.read_excel(file_errors_location) print(df) 
like image 67
Eric M Avatar answered Oct 20 '22 00:10

Eric M