How to read a .xlsx file using the pandas Library?

Given a .xlsx file, we have to read it using the pandas Library.
Submitted by Pranit Sharma, on June 11, 2022

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 the data.

Pandas DataFrames can be created with the help of dictionaries or arrays but in real-world analysis, first, a CSV file or an xlsx file is imported and then the content of CSV or excel file is converted into a DataFrame.

An xlsx 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:


To work with pandas, we need to import pandas package first, below is the syntax:

import pandas as pd

Let us understand with the help of an example,

# Importing pandas package
import pandas as pd

# Reading an xlsx file
data = pd.read_excel("D:/Book1.xlsx")

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


Example: Read a .xlsx file

Python Pandas Programs »


Comments and Discussions!


Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© some rights reserved.