I have this iteration:
with open("myFile.txt", "r") as landuse:
next(landuse)
for j in landuse:
landuseList = j.split(";")
clcKlasse = landuseList[2].strip()
landusePlz = landuseList[3].strip("\"")
landuseArea = landuseList[6].strip()
landuseAreaFloat = float(landuseArea.replace("," , "."))
if landusePlz in dictPlz:
areaPlz = dictPlz.get(landusePlz)
relativeShare = (landuseAreaFloat * 100) / areaPlz
nf.write(str(clcKlasse) + "\t" + str(relativeShare) + "\t")
prevAreaPlz = areaPlz
print "Done"
I need this structure in my file (nf
):
PLZ "abc" "def" "ghi" "jkl" "mnl" "opq"
1 7.54 1.20 9.98 19.57 8.68 2.15
PLZ "abc"
2 10.17
...
And thats the file where I read from:
"CLCKlasse";"PLZ";"area"
"abc";"1";7.54
"def";"1";1.20
"ghi";"1";9.98
"jkl";"1";19.57
"mnl";"1";8.68
"opq";"1";2.15
"abc";"2";10.17
...
AS you can see, each line relates to a plz
. But, I need the plz
only written once to nf
with each corresponding value in one line plus the headerline.