January 2019
Beginner
318 pages
8h 23m
English
When we use the pandas module to read an Excel file using the read_excel method, we can also read specific columns in that file. For reading specific columns, we need to use the usecols parameter in the read_excel method.
Now, let’s look at an example to read specific columns in an Excel file. Create a script called rd_excel_pandas1.py and write the following content in it:
import pandas as pdexcel_file = 'sample.xlsx'cols = [1, 2, 3]df = pd.read_excel(excel_file , sheet_names='sheet1', usecols=cols)print(df.head())
Run the preceding script and you will get the following output:
student@ubuntu:~/test$ python3 rd_excel_pandas1.py
Following is the output:
Region Rep Item0 Central Smith Desk1 Central ...
Read now
Unlock full access