How to read a specific row in excel file using python

20,461

Solution 1

You can also use pd.read_excel of pandas library:

You would need to install pandas and xlrd first:

import pandas as pd
import xlrd
df = pd.read_excel('abc.xlsx', sheet_name='Sheet1')

Now, you can filter your dataframe to get any specific row using iloc

df.iloc[6] ## This will give you 7th row

Solution 2

First install xlrd

pip install xlrd

then open python file and

import xlrd 

# Give the location of the file 
loc = ("path of file") 

# To open Workbook 
wb = xlrd.open_workbook(loc) 
sheet = wb.sheet_by_index(0) 

print(sheet.row_values(7)) 

location is relative path not absolute path.

To read more about xlrd and its usage visit https://xlrd.readthedocs.io/en/latest/

Happy coding.

Share:
20,461
Tim
Author by

Tim

Updated on January 24, 2020

Comments

  • Tim
    Tim over 4 years

    I want to read single row from an Excel_file1, Sheet1, Row number 7 using python, any help?