Python Practice › Pandas Programs › Program 95
Import an Excel file
Write a pandas program to import an .xlsx file.
Output
name marks 0 Asha 91 1 Ravi 78
Approach
pd.read_excel(needs openpyxl installed).
Solution
import pandas as pdpd.DataFrame({"name": ["Asha", "Ravi"], "marks": [91, 78]}).to_excel("marks.xlsx", index=False)df = pd.read_excel("marks.xlsx")print(df)Output
name marks 0 Asha 91 1 Ravi 78
Note
Install openpyxl first with python -m pip install openpyxl. The browser Try it does not include it.
Learn the concept
New to this topic? Read the lesson, then come back.