.read_excel()
The .read_excel()
function takes a path to an Excel file and reads the data into a Pandas DataFrame
object.
Syntax
pandas.read_excel(io, sheet_name)
The io
parameter is the path to the Excel file. It can be a path on the local machine or a valid URL. It is the first parameter of the function and can be used by itself.
The second parameter sheet_name
specifies the worksheet(s) to import. It can be a string, or list of strings to specify worksheet names, or it can be an integer or list of integers to specify zero-indexed sheet positions. (Chart sheets are ignored for this purpose.) Specifying None
will retrieve all worksheets. The default is 0
.
There are many other parameters that are optional or have default settings. These are usually passed as keyword arguments since using the parameter order is generally inconvenient.
Some of the more significant parameters are listed here:
Parameter Name | Data Type | Usage |
---|---|---|
io |
str | Path to the Excel file to import. |
sheet_name |
int, str, list of int, list of str | Worksheet names or indices. |
header |
int, list of int, None | Row number(s) to use as column names. |
names |
array-like | List of column names to use. |
usecols |
list-like or callable | Excel column letters or ranges, or column numbers, or column names to import. If callable, uses columns where the name passed to the callable results in True . |
skiprows |
list-like, int, or callable | Initial lines to skip (int) or line numbers to skip (list). Or callable that returns True when the row number passed to it should be skipped. |
Example
import pandasdf = pandas.read_excel("data.xlsx")print(df)
The output will show the contents of the Excel file loaded into the DataFrame:
column 1 column 2 column 30 A B C1 D E F
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn Python:Pandas on Codecademy
- Career path
Data Scientist: Machine Learning Specialist
Machine Learning Data Scientists solve problems at scale, make predictions, find patterns, and more! They use Python, SQL, and algorithms.Includes 27 CoursesWith Professional CertificationBeginner Friendly95 hours - Course
Learn Python 3
Learn the basics of Python 3.12, one of the most powerful, versatile, and in-demand programming languages today.With CertificateBeginner Friendly23 hours