It is not always possible to get the dataset in CSV format. So, Pandas provides us the functions to convert datasets in other formats to the Data frame. An excel file has a ‘.xlsx’ format.
Before we get started, we need to install a few libraries.
pip install pandas pip install xlrd
For importing an Excel file into Python using Pandas we have to use pandas.read_excel() function.
Syntax: pandas.read_excel(io, sheet_name=0, header=0, names=None,….)
Return: DataFrame or dict of DataFrames.
Let’s suppose the Excel file looks like this:
Now, we can dive into the code.
Example 1: Read an Excel file.
Example 2: To select a particular column, we can pass a parameter “index_col“.
Example 3: In case you don’t prefer the initial heading of the columns, you can change it to indexes using the parameter “header”.
Example 4: If you want to change the data type of a particular column you can do it using the parameter “dtype“.
Example 5: In case you have unknown values, then you can handle it using the parameter “na_values“. It will convert the mentioned unknown values into “NaN”
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.
- How to import excel file and find a specific column using Pandas?
- Create a GUI to convert CSV file into excel file using Python
- Different ways to import csv file in Pandas
- How to extract Time data from an Excel file column using Pandas?
- How to extract Email column from Excel file and find out the type of mail using Pandas?
- How to extract date from Excel file using Pandas?
- Find the sum and maximum value of the two column in excel file using Pandas
- How to import JSON File in MongoDB using Python?
- Exporting a Pandas DataFrame to an Excel file
- Combine Multiple Excel Worksheets Into a Single Pandas Dataframe
- Python | Writing to an excel file using openpyxl module
- Python | Arithmetic operations in excel file using openpyxl
- Python | Adjusting rows and columns of an excel file using openpyxl module
- Python | Trigonometric operations in excel file using openpyxl
- Python | Create and write on excel file using xlsxwriter module
- Reading an excel file using Python openpyxl module
- Reading an excel file using Python
- Convert CSV to Excel using Pandas in Python
- Joining Excel Data from Multiple files using Python Pandas
- How to Create a Pivot table with multiple indexes from an excel sheet using Pandas in Python?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.