sheets=['第一批','第二批','第三批']
count=0for sh in sheets:print('当前sheet:',sh)# DataFrame数据,可以转为numpy
data = pd.read_excel(excel_path,sheet_name=sh)# 不指定sheet_name默认只读第一个sheetprint(data.shape)#不含表头,data数据也不含表头
row, col = data.shape[0], data.shape[1]print(row, col)# 遍历获取单元格值for r inrange(row):
vin=data.iloc[r,0]# 第一列数据
vin_type=data.iloc[r,2]#第三列数据
2. 修改数据
data = pd.read_excel(excel_path)print(data.shape)
row,col=data.shape[0],data.shape[1]print(row,col)withopen(dayLOGResult,'r',encoding='utf-8')as f:
lines=f.readlines()for line in lines:
line=line.strip('\n')
line=line.split(' ')#有可能两个,有可能三个
vv=line[0]
ss=line[1]for r inrange(row):
vin=data.iloc[r,0]if vv==vin:# 向第二列位置写入值if ss=='1':
data.loc[r,coll]='1'elif ss=='-1':
data.loc[r,coll]='-1'#使用iloc报过错
writer = pd.ExcelWriter(excel_path)# 写入Excel文件
data.to_excel(writer, sheet_name='sheet1', index=False)# ‘sheet1’是写入excel的sheet名
writer.save()
writer.close()