Today, a classmate gave me an Excel file, asked to read some rows, some columns, and then I tried to do a demo, here to share out, hoping to help everyone:
First install XLRD:
PIP3 Install XLRD
And then the code:
Import NumPy as NP
import xlrd
data = Xlrd.open_workbook (' lifetable_16.xlsx ')
table = data.sheets () [0] #
Print (table)
# nrows = table.nrows #行数
# ncols = table.ncols #列数
# c1=arange (0,nrows,1)
# Print (c1
start=6 #开始的行
end=106 #结束的行
rows=end-start
list_values=[] for
x in range ( Start,end):
values=[]
row =table.row_values (x) for
I in range (1,7):
# Print (value)
Values.append (Row[i])
list_values.append (values)
# Print (list_values)
Datamatrix=np.array (list_ Values)
print (Datamatrix)
Reference Documents
[The 1].numpy array and the list in Python are transformed from one to the other. https://blog.csdn.net/baiyu9821179/article/details/53365476
[2]. python-stores the data in Excel inside the matrix. https://blog.csdn.net/cmdtth/article/details/52278049