WPS Office

Free All-in-One Office Suite with PDF Editor

correct-icon

Edit Word, Excel, and PPT for FREE.

correct-icon

Read, edit, and convert PDFs with the powerful PDF toolkit.

correct-icon

Microsoft-like interface, easy to use.

Free download

Windows • MacOS • Linux • iOS • Android

banner

How to read excel file in python using pandas (Step by Step)

July 22, 2022
3.4K Views

Excel is a software program which consists of various tools and operations which are used for the storage and analysis of data and representation of financial data inform of charts and graphs. Excel is of prime importance in the world of business and accounting but there are several drawbacks of excel in analysis of data.

These drawbacks can be removed by processing the data of excel on python .Python is a collection of data in compiled form. Python is a platform of data analysis and data science. It plays a vital role in upgrading data and analytics. Reading of excel file in python is a successful and feasible approach. Python is a representation of integrated data which has made the extraction of information accessible. The skill of reading excel files in python is critical and technical. But there are some ways that simplify this process. In this article we will highlight some important codes of reading excel file in python.

How to read excel file in python by installing xlrd module

For attaining information from a spread sheet xlrd module is used. Organization and extraction of data is performed by xlrd module. Without xlrd module users face difficulties in retrieving modifying data .xlrd is installed by a command that is:

pip install xlrd

How to read excel file in python by creating a workbook

A workbook is collection of entire data of the excel file. It contains all the information that is present in excel file. A work book can be created on excel.

  1. At first we have installed xlrd module then we will define the location of the file by using the following code

loc=(path of file)

  1. Then we will open the workbook that we have already created on excel or we can also open the workbook by applying the following code

Wb=xlrd.open_workbook(loc)

sheet=wb.sheet_by_index(0)

  1. After opening the workbook we will enter code for rows and columns. Suppose we have 0 rows and 0 columns then the code will be

sheet.cell_(0,0)

  1. The output of the above process will be creation of a work book consisting of a localized data in definite rows and columns.

 How to read excel file in python using pandas

Excel files can be imported in python using pandas. Pandas is an open- source library which consists of very useful feature such as cleaning of data, analysis at high speed and presented users with well-organized and refined data. For reading excel files in python using pandas

  1. First, we have to select the full path which contains the entire data of excel. Suppose the excel file we will use is stored under the following path

C:\User\dt\Desktop\List of Names.xlxs

  1. Then we will import the file in xlrd module

Import pandas as pd

  1. Then we will apply the python code

df = pd.read_excel (r'C:\Users\dt\Desktop\List of Selling Products.xlsx')r '\'. C:\User\dt\Desktop\List of Names.xlxs+ '.xlsx' print (df)

  1. Lastly we will run the python code to get our finalized data which is same as excel file.

Did you learn about how to read an excel file in python using different methods? You can follow WPS Academy to learn more features of Word Document, Excel Spreadsheets, and PowerPoint Slides.

You can also download WPS Office to edit the word documents, excel, and PowerPoint for free of cost. Download now! And get an easy and enjoyable working experience. 

15 years of office industry experience, tech lover and copywriter. Follow me for product reviews, comparisons, and recommendations for new apps and software.