Read Excel in Python Pandas

To read an Excel file in Python, we use the Pandas read_excel() method. First, install the openpyxl package using pip. Type the following command to install openpyxl:

Let’s say we have the following Excel file Cricket.xlsx:

read excel python pandas

Read an Excel

Let us now see an example to read our Excel file Cricket.xlsx using the pandas.read_excel() method in Pandas. First, load the Excel file, read the data, and store it in a Pandas DataFrame:

Output

Display the top n rows of the DataFrame

The head() method will display the first n rows of a DataFrame. The default rows returned are 5.

Let us see an example to display only the top 2 rows. For that, set the parameter of the head() as 2. First, load the Excel file, read the data, and store it in a Pandas DataFrame:

Output

Display the last n rows of a DataFrame

The tail() method will display the last n rows of a DataFrame. The default rows returned are 5.

Let us see an example to display only the bottom 2 rows. For that, set the parameter of the tail() as 2. First, load the Excel file, read the data, and store it in a Pandas DataFrame:

Output


If you liked the tutorial, spread the word and share the link and our website Studyopedia with others.


For Videos, Join Our YouTube Channel: Join Now


 

Select multiple columns in a Pandas DataFrame
Add a new column to Pandas DataFrame
Studyopedia Editorial Staff
contact@studyopedia.com

We work to create programming tutorials for all.

No Comments

Post A Comment

Discover more from Studyopedia

Subscribe now to keep reading and get access to the full archive.

Continue reading