文件“删除最小值.xlsx”中,(A:D)四列数据,希望删除每行的最小值,保留三个值,写入到后面(F:H)列中。
#调入 openpyxl库 import openpyxl #2、打开文件,定义表单: wb = openpyxl.load_workbook(“c:\删除最小值.xlsx”) sht = wb[‘数据’] #3、数据处理(请自动忽略粗糙的逻辑思路) for i in range(2, 8): minnum = sht.cell(i,1).value print(minnum , sht.cell(i,1).value) if sht.cell(i, 2).value < minnum: minnum = sht.cell(i,2).value if sht.cell(i,3).value < minnum: minnum = sht.cell(i,3).value if sht.cell(i, 4).value < minnum: minnum = sht.cell(i,4).value k = 0 for j in range(1,5): if sht.cell(i, j).value > minnum: k += 1 sht.cell(i,k+5).value = sht.cell(i,j).value print(sht.cell(i, k+5).value, end=’ ‘) print() #4、保存文件: wb.save(“c:\删除最小值.xlsx”)
http://toutiao.com/group/6762179541545779720/?iid=0&app=news_article