Ich bin neu in Python und habe gearbeitet, um eine Excel-Tabelle zu analysieren. Ich versuche den kumulierten Wert zu ermitteln, der mit einer bestimmten Zonierung über eine Reihe von Daten verbunden ist.Überschreiben aller Werte beim Iterieren einer for-Schleife - Python
Ich habe das Gefühl, dass ich den logischen Fluss nicht richtig verstehe, denn egal wie ich es schreibe, ich komme immer wieder mit einem Wörterbuch von Werten, die alle gleich sind. An diesem Punkt habe ich keine Ahnung, warum es falsch ist. Anstatt es zu beschreiben, möchte ich es direkt angehen.
Die hoursAllocationDict wie folgt aussieht:
5-21-16
Zoning1: 0
Zoning2: 0
Zoning3: 0
5-22-16
Zoning1: 0
etc...
Meine rawData wie eine Liste von Listen aus:
[0] NAME, data, data, data, DATE, data, HOURS, data, ZONING, data, data, data, etc.
[1] NAME, data, data, data, DATE, data, HOURS, data, ZONING, data, data, data, etc.
[2] NAME, data, data, data, DATE, data, HOURS, data, ZONING, data, data, data, etc.
Der Codeblock Ich bin für diese Aufgabe ausgeführt wird wie folgt aussieht:
#Iterate over all dates - date is a tuple with 0 index being the date and 1 being a dict of zonings
for date in hoursAllocationDict.iteritems():
#Iterate over each row
for row in rawData:
#If cell is not empty or blank AND if date cell equals iterator date
if rawData[row][23] and rawData[row][9] == date[0]:
#Use re.search to match possible zoning in zoning column (found in string of otherwise irrelevant data)
if findZoningInCell(rawData[row][23], zoningsDict):
#Store whatever subjoining we find
subZoning = findZoningInCell(rawData[row][23], zoningsDict)
#rawData[row][18] references a value of hours related to zoning
#Accumulate x.x hrs in hoursAllocationDict -> date -> subjoining
hoursAllocationDict[rawData[row][9]][subZoning] += rawData[row][18]
Der Endzustand der StundenAllocationDict sieht folgendermaßen aus:
'10-29-15' : 'Zoning1': 52.0, 'Zoning2': 100.08333333333333, 'Zoning3': 128.0, 'Zoning4': 594.0, etc...
'10-30-15' : 'Zoning1': 52.0, 'Zoning2': 100.08333333333333, 'Zoning3': 128.0, 'Zoning4': 594.0, etc...
'10-31-15' : 'Zoning1': 52.0, 'Zoning2': 100.08333333333333, 'Zoning3': 128.0, 'Zoning4': 594.0, etc...
....
....
Also bin ich irgendwie aktualisiert alle Werte aller Schlüssel des Wörterbuchs jeder Iteration, aber ich kann einfach nicht sehen, wie. Ich habe es ein paar Mal umgeschrieben, um jetzt zu nutzen.