ich bräuchte mal wieder euer Hilfe. Ich habe als Input ein File welches 3 Spalten enthält:
VON , BIS , ID
('04.07.2013', '31.07.2013', '292'),
('01.08.2013', '11.08.2013', '292'),
('04.03.2013', '31.03.2013', '293'),
('01.04.2013', '05.04.2013', '293'),
('06.04.2013', '02.06.2013', '293'),
('03.06.2013', '07.06.2013', '293'),
('09.09.2013', '20.09.2013', '293'),
('22.05.2013', '24.05.2013', '303')
Mein Programm soll nun die Datensätze mit gleicher ID und durchgehenden Zeitraum zusammenfügen, dass Ergebis sollten dann sein:
('04.07.2013', '11.08.2013', '292'),
('04.03.2013', '07.06.2013', '293'),
('09.09.2013', '20.09.2013', '293'),
('22.05.2013', '24.05.2013', '303')
Bis jetzt kann mein Programm nur 2 Datensätze zusammenfügen, jedoch nicht mehrere:
Code: Alles auswählen
while i < len(idlist)-1:
if idlist[i][2] != idlist[i+1][2]:
idlist2.append(idlist[i])
if idlist[i][2] == idlist[i+1][2]:
print "i", idlist[i]
# Wenn Zeile1 Tag+1 und Zeile2 Tag gleich sind und auch der Monat gleich sind
if ((int((idlist[i][1])[:2])+1 == int((idlist[i+1][0])[:2])) and (((idlist[i][1])[3:])[:2]) == (((idlist[i+1][0])[3:])[:2])):
idlist2.append((idlist[i][0],idlist[i+1][1],idlist[i][2]))
i = i+1
# Wenn Zeile 1 Tag gleich 31 und Zeile 2 Tag 01, dann muss Zeile 1 den Monat "01" or "03" or "05" or "07" or "08" or "10" or "12" haben
elif (idlist[i][1])[:2] == "31" and (((idlist[i][1])[3:])[:2]) == "01" or "03" or "05" or "07" or "08" or "10" or "12":
if (idlist[i+1][0])[:2] == '01':
idlist2.append((idlist[i][0],idlist[i+1][1],idlist[i][2]))
i = i+1
# Wenn Zeile 1 Tag gleich 30 und Zeile 2 Tag 01, dann muss Zeile 1 den Monat "04" or "06" or "09" or "11"
elif (idlist[i][1])[:2] == "30" and (((idlist[i][1])[3:])[:2]) == "04" or "06" or "09" or "11":
if (idlist[i+1][0])[:2] == '01':
idlist2.append((idlist[i][0],idlist[i+1][1],idlist[i][2]))
i = i+1
# Wenn Zeile 1 Tag 28 oder 29 und Zeile 2 Tag 01, dann muss Zeile 1 den Monat "02"
elif (((idlist[i][1])[:2]) == "28" or "29") and ((((idlist[i][1])[3:])[:2]) == "02") and ((idlist[i+1][0])[:2]) == '01':
idlist2.append((idlist[i][0],idlist[i+1][1],idlist[i][2]))
i = i+1
else:
print "else", idlist[i]
idlist2.append(idlist[i])
i = i+1
Dank vorab und Quack
DER FROSCH
