GUVI
Back

Please update this lesson Guvi Team🐱‍💻 (IIT-M Python Course (Read Excel Data in Python 🐞))  

Created 2 years ago
98 Views
2 Comments
Akboss
@Akboss
Akboss
@AkbossProfile is locked. Login

Hello Guvi, This is Arun Kumar

(IIT-M Python Course (Read Excel Data in Python 🐞))  In this lesson (Read Excel Data in Python 🐞) the guy was teaching older version xlrd 1.7.0 so he can run the code( Read,Write). But I installed xlrd 2.0.1(New version) using is method pip install xlrd in cmd. I can't read or write the excel file in python and it gave me an Error !!🤨

Traceback (most recent call last):

File "E:\Kali\Program Testing\Python Testing\exceltesting.py", line 5, in <module>

wb = xlrd.open_workbook(loc_file)

File "C:\Users\ELCOT\AppData\Local\Programs\Python\Python39\lib\site-packages\xlrd\__init__.py", line 170, in open_workbook

raise XLRDError(FILE_FORMAT_DESCRIPTIONS[file_format]+'; not supported')

xlrd.biffh.XLRDError: Excel xlsx file; not supported

[Finished in 530ms]

Then I search the Error🐞 in the web and i a got solution that was xlrd 2.0.0 and above can only read .xls files not xlsx files. Support for .xlsx files was removed from xlrd due to a potential security vulnerability. In this website (Microsoft official site) : https://docs.microsoft.com/en-us/azure/databricks/kb/libraries/xlsx-file-not-supported-xlrd

And the Solution was :

Use openpyxl to open .xlsx files instead of xlrd.

  1. Install the openpyxl library on your cluster.

  2. Confirm that you are using pandas version 1.0.1 or above.

    PythonCopy

    import pandas as pd
    print(pd.__version__)
    
  3. Specify openpyxl when reading .xlsx files with pandas.

    PythonCopy

    import pandas
    df = pandas.read_excel(`<name-of-file>.xlsx`, engine=`openpyxl`)
    

Refer to the openpyxl documentation for more information.

Loading from a file in openpyxl

The same way as writing, you can use the openpyxl.load_workbook() to open an existing workbook:

>>> from openpyxl import load_workbook
>>> wb2 = load_workbook('test.xlsx')
>>> print(wb2.sheetnames)
['Sheet2', 'New Title', 'Sheet1']

I learn the code and i run it !! as Beginner 🙂

But lessons are take into openpyxl and pandas module(Library) not in xlrd module so please update the lesson with pandas in (IIT-M Python Course (Read Excel Data in Python 🐞)) . I hope you will be see my post and please update it

Build a wonderful GUVI Community as learner.

By Arun Kumar 😎

Comments (2)
Please login to comment.
 
Powered by habitate.io Habitate