For this Python example, the Excel file we will use for read is the following:
This is a single sheet Excel file.
If you are working from Linux Ubuntu you must execute the following command in the terminal to download the libraries and install Pandas.
sudo apt install python3-pandas
The code in Python is very simple, we will use Pandas so you have to do the corresponding import.
import pandas as pd # geekole.com excel_file = pd.read_excel('/path/ExcelExample.xlsx') print(excel_file.columns) values = excel_file['Identifier'].values print(values) columns = ['Identifier', 'Name', 'Surnames'] df_selected = excel_file[columns] print(df_selected)
It is also important to import the xlrd package
pip install xlrd
Once the file has been read, it is possible to obtain the names of the columns of the Excel file with: file_excel.columns
Later it is possible to extract the content of the entire document with the following lines:
columns = [‘Identifier’, ‘Name’, ‘Surnames’]
df_selected = excel_file[columns]
And that would be all, we hope this example about of read an Excel file in Python will help you.