这个列表是从我创建的一个Excel文档中产生的,其中表1有通道编号,表2有瓦数值,如果通道处于低值和高值之间。在试图保持一个列表与确切的位置,它是在相关的Excel文档。我能找到的唯一方法是从for语句中获取,并将其作为行号追加到下面的结果中。这恰好是来自频道号的瓦特数。我是新的Python,新的张贴在这里请容忍我,如果我搞砸了代码正确张贴。我记得上次我搞砸了很多。
[0, 1225, 1, 160, 1, 160, 1, 160, 1, 160, 1, 350, 1, 350, 1, 350, 1, 350, 2, 870, 2, 870, 3, 582, 3, 582, 3, 582, 3, 582, 3, 582, 4, 161, 4, 161, 4, 161, 4, 161, 4, 161, 5, 1225, 6, 870, 6, 870, 7, 1225, 8, 582, 8, 582, 8, 582, 8, 582, 9, 160, 9, 160, 9, 160, 10, 161, 10, 161, 10, 161, 10, 161, 10, 161, 11, 1225, 12, 870, 12, 870, 13, 582, 13, 582, 13, 582, 13, 582, 13, 582, 14, 160, 14, 160, 14, 160, 15, 161, 15, 161, 15, 161, 15, 161, 15, 161, 16, 1225, 17, 1225, 18, 1225, 18, 1225, 19, 160, 19, 160, 19, 160, 19, 350, 19, 350, 19, 350, 19, 350, 20, 160, 20, 870, 20, 870, 21, 582, 21, 582, 21, 582, 21, 582, 21, 582, 22, 161, 22, 161, 22, 161, 22, 161, 22, 161, 24, 870, 24, 1225, 25, 870, 25, 1225, 26, 582, 26, 582, 26, 582, 26, 582, 27, 160, 27, 160, 27, 160, 28, 161, 28, 161, 28, 161, 28, 161, 28, 161, 30, 870, 30, 870, 31, 582, 31, 582, 31, 582, 31, 582, 31, 582, 32, 160, 32, 160, 32, 160, 33, 161, 33, 161, 33, 161, 33, 161, 33, 161, 34, 1225, 34, 1225, 37, 900, 37, 900, 38, 900, 38, 900, 39, 820, 41, 820, 41, 900, 42, 900, 42, 900, 44, 820, 44, 900, 47, 900, 47, 900]
你会注意到这只是一个列表如果你有办法,我可以用这些发现创建一本字典,我很想听听。我使用Pandas来获得上面给我的列表的比较。我的下一步是你注意到之前的3位数字是一个数字,反映了在同一行从Excel文件。正如你所看到的,1有160和350个值。我一直在寻找一个循环来遍历列表,如果value是1,那么totalWatts += 160 += 350等。等等,其在每一行将附加另一个列表,该列表是该行的总瓦特数。我不确定Pandas是否是最好的选择,或者是否有另一个更好的选择。第一行的答案是totalLineWatts.append(totalWatts),它将给予一个列表,我将把它带到oop中,在excel中计算该行的安培数,其总数为2040。我可以看到,我也将做另一个附加之前,总瓦特与数字,因为有些行是失踪,这是因为该行没有渠道的Excel文档。因此,如果有人能告诉我一个例子,如何通过这一步,这将是非常感谢。
从非OOP版本添加一些工作代码。只允许5个频道。我正在创建一个允许无限通道每电路。但在计算这些是我试图解决上述问题。看看一个工作代码,只计数5的通道线。
counter3 = 0
channelNums3 = []
thirdRowWatts = 0
thirdLineAmps = []
thirdVolts = wattSheet['Voltage'][2]
thirdActualWatts = []
thirdSection = []
for h in range(27, 33, 1):
for j in range(4, 9, 1):
channelNums3.append(df.loc[h, j])
thirdSection = channelNums3[:5]
for e in range(5):
f = thirdSection[e]
for g in range(rowCount - 2):
thirdChanLow = wattSheet['ChanLow'][g]
thirdChanHi = wattSheet['ChanHigh'][g]
if f in range(thirdChanLow, thirdChanHi):
thirdWatts = wattSheet['Wattage'][g]
thirdRowWatts += thirdWatts
thirdLineAmps.append(round((thirdRowWatts/thirdVolts/2), 2)) # gets my amps per leg
thirdActualWatts.append(thirdRowWatts)
print(thirdSection)
print(f"Actual watts this circuit is {thirdActualWatts[-1]}") # this circuits total watts
print(f"Total Watts: {thirdRowWatts} / Voltage {thirdVolts} / 2 legs = {thirdLineAmps[-1]}")
print(thirdLineAmps)
thirdRowWatts = 0 # resets thirdRowWatts variable for the next circuit check.
channelNums3 = [] # resets list so the slice works
# TODO Below is the inserting into the excel Document for the 3rd section Backed up to github as 3rd working
# example sheet2.range("C4", "D4").value = lineAmps[0]
sheet2.range("C29", "D29").value = thirdLineAmps[0]
sheet2.range("D30", "E30").value = thirdLineAmps[1]
sheet2.range("C31").value = thirdLineAmps[2]
sheet2.range("E31").value = thirdLineAmps[2]
sheet2.range("C32", "D32").value = thirdLineAmps[3]
sheet2.range("D33", "E33").value = thirdLineAmps[4]
sheet2.range("C34").value = thirdLineAmps[5]
sheet2.range("E34").value = thirdLineAmps[5]
该代码在5个通道的6个电路中计数。可以计算无限频道的代码可以计算无限频道。我只是很难计算一条线的总瓦特数。而不计算其他的瓦特,因此上述第一个代码1 = 2040。谢谢关于我的东西不能回答,因为一个糟糕的问题。所以我编辑第一个发布我的工作,让我计算的行,我想在顶部。
circTotalWatts1 = []
class CircWatts:
def __init__(self) -> None:
self.rackSize = 48
self.circTotalWatts = []
def circuitWatts(self, dfWatts):
for x in range(self.rackSize):
lineTotal = int(dfWatts.iloc[x].sum())
circTotalWatts1.append(lineTotal)
self.circTotalWatts = pd.DataFrame(circTotalWatts1)
return self.circTotalWatts
我知道如果没有www.example.com,这是没有意义main.py,但我知道必须有一种方法来计算这一行,并分离南行。希望这能让我摆脱stackOverflow的麻烦。
1条答案
按热度按时间vom3gejh1#
这个问题被标记为excel,但提供的代码是python。如果没有样本excel文件/完成一种方法来重现的情况下,我可能只是分享一种替代方法来获得结果。使用Excel。希望足够了。
假设列表中的数据位于A1:A245。做:
=COUNT(A:A)
=SUM(--(FREQUENCY(D:D,D:D)>0))
=IF(ROW()>$B$1/2,"",INDIRECT("A"&((ROW()-1)*2+1)))
=IF(ROW()>$B$1/2,"",INDIRECT("A"&((ROW()-1)*2+2)))
=IF(ROW()>$B$1/2,"",IF(ROW()=1,1,IF(ROW()>$B$1,"",IF(OFFSET(D2,-1,0)<>OFFSET(D2,-2,0),OFFSET(F2,-2,0)+1,OFFSET(F2,-2,0)))))
=IF(ROW()>MAX(F:F),"",INDEX(D:D,MATCH(ROW(),F:F,0)))
=IF(ROW()>MAX(F:F),"",SUMIF(D:D,G1,E:E))
然后选择D1:H1,向下拖动它们。完了
你会得到列G作为你的唯一频道列表,列H是它的单独总和。
想法:
注意:我故意没有使用FILTER()函数,这样它就可以在非365 Excel上工作。