import pandas as pd
df=pd.read_excel(“D:/Python/05DataMineML/2022STU(1).xlsx”)
df
但是分明是有数据的,大概率出现的原因是sheetname
(表的名称)出现了问题。
那就试试其他的方法:
下图是Excel的表头,共有115行数据。
方法一:使用usecols
#获取字段的第一种写法
import pandas as pd
df=pd.read_excel(‘…/05DataMineML/2022STU(1).xlsx’,usecols=[‘学号’,‘姓名’,‘20220101’,‘20220125’,‘20220202’,‘20220208’,‘20220213’,‘20220220’,‘20220226’,‘20220311’,‘20220320’,‘20220327’,‘20220403’,‘randscore’],index_col=‘姓名’,sheet_name=‘2022STUMOOC’)
df.info()
index_col:指定作为表格的索引值
usecols:pandas读取excel使用read_excel()中的usecols参数读取指定的列
sheet_name:表名