ImportError: No module named 'xlrd'

Learn about the ImportError: No module named 'xlrd' error in Python, and how to fix it?
Submitted by Pranit Sharma, on September 24, 2022

Pandas is a special tool that allows us to perform complex manipulations of data effectively and efficiently. Inside pandas, we mostly deal with a dataset in the form of DataFrame. DataFrames are 2-dimensional data structures in pandas. DataFrames consist of rows, columns, and data.

'xlrd' Module

'xlrd' module is a special module in python which is used while using pandas.read_excel() to open an excel file.

An excel file is a spreadsheet file that can be created with certain software, especially with the popularly known MS Excel. To import an Excel file, we use the following piece of code:

Sometimes, while importing this excel file, we observe an error called "No module named xlrd".

How to Fix: ImportError: No module named 'xlrd'?

For this purpose, we first need to install the xlrd module by writing the following command in the command prompt window.

Command to Install "xlrd" Module

pip install xlrd

Below is the implementation:

Command to Install 'xlrd' Module

Now once xlrd module is imported, we can easily import an excel file from our local machine.

Let us understand with the help of an example,

Python code to read an excel file without ImportError: No module named 'xlrd'

# Importing pandas package
import pandas as pd

# Reading an xlsx file

data = pd.read_excel("E:/Includehelp/Book1.xlsx")

# Display data

print("Records from the Excel sheet:\n",data)

Output

The output of the above program is:

Fix: ImportError: No module named 'xlrd'

Python Pandas Programs »

Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.