IrisExample/main.py

29 lines
942 B
Python

import csv
def analyze_iris():
result=[]
wortDict={}
with open("Iris.csv", mode='r', encoding='utf-8') as file:
reader = csv.reader(file)
next(reader, None) # skip the header if present
for row in reader:
txt=row[5]
tmpValues=row[1:5] # slice row array id
tmpValues=[float(x) for x in tmpValues] # Convert from string to float array - typecasting
tmpObj = {}
tmpObj["max"] = max(tmpValues) # max Value
tmpObj["min"] = min(tmpValues) # min Value
tmpObj["avg"] = round(sum(tmpValues)/len(tmpValues),2) #durchschnitt und runde auf zwei kommastellen
result.append(tmpObj)
wortDict[txt] = wortDict.get(txt, 0) + 1
result.append(wortDict)
return result
result = analyze_iris()
#print(result)
print("\n".join([str(i) for i in result]))