我似乎将自己与循环混淆,无法修复,我希望生成一个数据集,该数据集在我的 excel 表中向右和向下移动,但由于某种原因,每个新行都会在第一行的末尾被截断,因此我的回溯错误,试图读取上面的空单元格。我希望能有一些新鲜的眼光,因为我后来的代码依赖于这个正确的输出,希望它能够解决全球经济衰退,或者不是,但会让我成为一个快乐的人。:)
import datetime
import random
import numpy as np
import math
import sys
from openpyxl import Workbook
from openpyxl.cell import get_column_letter
from openpyxl import load_workbook
from tempfile import TemporaryFile
from random import normalvariate, expovariate, seed, gammavariate
from math import sqrt
from itertools import groupby
for week in CurrentWeek:
Global_counter = week
i = Global_counter
j = 52 + i
if Global_counter == 1:
for index in range(i,j,1):
PlanWeek = index
EC_D = 500.0
if EC_D <= 0:
EC_D = EC_D *(-1)
EC_PlanData.append(EC_D)
d = sheet1.cell(row = Global_counter, column = PlanWeek)
d2 = sheet2.cell(row = Global_counter, column = PlanWeek)
d.value = EC_D
d2.value = EC_D
else:
for index in range(i,j,1):
PlanWeek = index
DiffWeek = PlanWeek - Global_counter
Sigma = 1
mu = 0
FC_VZ = random.normalvariate(mu, Sigma)
if FC_VZ > 0:
FC_VZ = 1
FC_Error = FC_Error+RemainingFCError
fcerr = sheet5.cell(row = Global_counter, column = PlanWeek)
fcerr.value = FC_Error
Prev_Week = Global_counter - 1
ECDD1 = sheet1.cell(row=Prev_Week, column=PlanWeek).value
ECDD2 = sheet1.cell(row=Prev_Week, column=PlanWeek).value
EC_D = ECDD1 - (ECDD2*FC_Error)
FC_Error = 0
ECPD = sheet1.cell(row = Global_counter, column=PlanWeek)
ECPD.value = EC_D
FCAD = sheet6.cell(row = Global_counter, column=PlanWeek)
FCAD.value = FC_Error
IEFD = sheet2.cell(row = Global_counter, column=PlanWeek)
IEFD.value = EC_D
EC_D = 0
wb.save('RHF_Loop_test4py.xlsx')
我的追溯是:
Traceback (most recent call last):
File "C:\Python27\Darren Learning Samples\codetesting2.py", line 85, in <module>
EC_D = ECDD1 - (ECDD2*FC_Error)
TypeError: unsupported operand type(s) for *: 'NoneType' and 'float'