habe mir nun einen code erstellt der sich aus csv files daten ausliest und verschiedene berechnungen anstellt, das ganze passiert in einer for line schleife
ich will jetzt die ergebnisse sammeln aneinander hängen und als csv file ausgeben
zb
year,monat,day index1,index2
habe jetzt schon mit zip und ähnlichem ru probiert aber es läuft noch nicht so richtig
für hilfestellungen immer dankbar
a
Code: Alles auswählen
import os
import csv
def calculateIndices(days):
fmi(days,temp,hum) ## calculate humidity....
def fmi(days):
for i in range(0,days):
#output.index1[i] = 10 - 0.25* (data.temp[i] - data.hum[i])
index1[i] = 10 -0.25*(temp[i]-hum[i])
workingdir ="E:\\Programme\\eclipse\\workspace\\learning"
hum=[]
tag= []
monat=[]
temp=[]
prec=[]
tempmean=[]
daysofmonth=[]
index1=[]
for i in range( 0,366):
monat.append(0)
temp.append(0)
hum.append(0)
index1.append(0)
for i in range( 0,12):
tempmean.append(0)
daysofmonth.append(0)
names = os.listdir(workingdir)
try:
outputfile =open("output_selected.csv","w")
except:
print("daten zugriff nicht moeglich")
sys.exit()
for name in names:
fileext = os.path.splitext(name)[-1]
if ".csv" == fileext:
file = csv.reader(open(name),delimiter=";")
### create output file
doy = 0;
for line in file:
if(file.line_num > 1):
month = int(line[2])
day = int(line[3])
if month==1 and day==1:
year = int(line[1])
doy=0
for i in range(0,12):
tempmean[i]=0
daysofmonth[i]=0
if month==2 and day==29:
continue
monat[doy]=month
temp[doy]=float(line[4])
hum[doy]=float(line[6])
tempmean[month-1]+=temp[doy]
daysofmonth[month-1]+=1
doy = doy + 1
if month==12 and day==31:
for i in range(0,12):
tempmean[i]=tempmean[i] / daysofmonth[i]
# calc indices
fmi(doy)
print(year)
print (monat)
print(temp)
print(tempmean)
print(daysofmonth)
print(index1)
#writeOutputs()
### file finished
print ("file finished")