我想使用Python从Excel_file1的Sheet1中读取第7行的单元格数据,可以帮忙吗?
我想使用Python从Excel_file1的Sheet1中读取第7行的单元格数据,可以帮忙吗?
首先安装xlrd
pip install xlrd
然后打开Python文件并
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))
位置是相对路径而不是绝对路径。
要了解更多关于xlrd及其使用的信息,请访问https://xlrd.readthedocs.io/en/latest/
愉快的编码。
您也可以使用pd.read_excel
函数,该函数属于pandas
库:
您需要先安装pandas
和xlrd
:
import pandas as pd
import xlrd
df = pd.read_excel('abc.xlsx', sheet_name='Sheet1')
iloc
筛选数据框以获取任何特定行。df.iloc[6] ## This will give you 7th row