老师请帮忙看一下这个错误是怎么产生的,尝试了很久还是修改不好
import xlrd
from xlutils.copy import copy
def read_data():
wb = xlrd.open_workbook('./imp_data/data1.xlsx')
sh = wb.sheet_by_index(0)
fen_type = {} #ABC每个类型中所有产品的总价格
count_price = [] #每个商品的总价格
for i in range(sh.nrows):
count = sh.cell_value(i,3) * sh.cell_value(i,4)
count_prince.append(count)
key = sh.cell_value(i,0)
if fen_type.get(key):
fen_type[key] += count
else:
fen_type[key] = count
return fen_type,count_price
def save(fen,count):
wb = xlrd.open_workbook('./imp_data/data1.xlsx')
sh_t = wb.sheet_by_index(0)
wb2 = cpoy(wb)
sh = wb2.get_sheet(0)
for i in range(sh_t.nrows):
sh.write(i,sh_t.ncols,count[i])
sh2 = wb2.add_sheet('汇总数据.xlsx')
for i,key in enumerate(fen.keys()):
sh2.write(i,0,key)
sh2.write(i,1,fen.get(key))
wb2.save('./cerate_data/data2.xlsx')
if __name__ == '__main__':
f,c = read_data()
save(f,c)
