Python的新手。此后尝试将G3中使用的公式应用于所有G列,但随着输出单元格的移动,该公式的值也会随之移动。
当前函数成功地获得了G3的期望值,但只需对G列中其余单元格重复该值。希望它根据下一行的值重新计算。
def getStochastic():
# *** Replaced with newNewList(s)
# listLow = [ws['D3'].value, ws['D4'].value, ws['D5'].value, ws['D6'].value, ws['D7'].value, ws['D8'].value, ws['D9'].value, ws['D10'].value, ws['D11'].value, ws['D12'].value, ws['D13'].value, ws['D14'].value, ws['D15'].value, ws['D16'].value, ws['D17'].value]
# listHigh = [ws['C3'].value, ws['C4'].value, ws['C5'].value, ws['C6'].value, ws['C7'].value, ws['C8'].value, ws['C9'].value, ws['C10'].value, ws['C11'].value, ws['C12'].value, ws['C13'].value, ws['C14'].value, ws['C15'].value, ws['C16'].value, ws['C17'].value]
maxRow = ws.max_row
next_row = 3
for row in ws.iter_rows(min_col=7, max_col=8, min_row=3, max_row=maxRow):
for value in row:
iteration = 3
small = 1
large = 14
maxRow = ws.max_row
lowList = ws['D' + str(iteration):'D' + str(large)]
newLowList = []
for columnList in lowList:
for val in columnList:
valList = [val.value]
newLowList.append(valList)
newNewLowList = [j for i in newLowList for j in i]
highList = ws['C' + str(iteration):'C' + str(large)]
newHighList = []
for columnList in highList:
for val in columnList:
valList = [val.value]
newHighList.append(valList)
newNewHighList = [j for i in newHighList for j in i]
xLow = min(float(s) for s in newNewLowList)
yHigh = max(float(s) for s in newNewHighList)
percentKTop = float(ws['E'+ str(iteration)].value) - float(xLow)
percentKBot = (float(yHigh) - float(xLow))
percentK = ((percentKTop) / (percentKBot)) * 100
ws.cell(column=7, row=next_row, value=percentK)
next_row += 1
iteration += 1
large += 1