Pandas: Reading .xlsx or .xls Excel Files



To read an Excel file using Python pandas we can make use of the read_excel() method, this will return the Excel data in tabular form as a dataframe.


Microsoft Excel file: data.xlsx

Excel xlsx file to be read using Python Pandas

Example:

import pandas as pd

excel_file = 'data.xlsx'

dataframe = pd.read_excel(excel_file)
print(dataframe.head())
Output:
% python3 example.py

        Date  Temp
0 2023-01-01    22
1 2023-02-01    22
2 2023-03-01    21
3 2023-04-01    20
4 2023-05-01    19

Do checkout the official pandas documentation on read_excel method: https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.read_excel.html

-

Facing issues? Have Questions? Post them here! I am happy to answer!


Author Info:

Rakesh is a seasoned developer with over 10 years of experience in web and app development, and a deep knowledge of operating systems. Author of insightful How-To articles for Code2care.

Follow him on: X

Copyright © Code2care 2023 | Privacy Policy | About Us | Contact Us | Sitemap