From 923b007054634ab04dcd73c5db3c373023dd2dd8 Mon Sep 17 00:00:00 2001 From: Ermis Wieger Date: Wed, 29 Jan 2025 18:39:22 +0100 Subject: [PATCH] changed to transponded --- main.py | 41 +++++++++++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 12 deletions(-) diff --git a/main.py b/main.py index bb47e2a..64abd26 100644 --- a/main.py +++ b/main.py @@ -2,28 +2,45 @@ import csv def analyze_iris(): + result=[] wortDict={} - + values=[] 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 + values.append(tmpValues) + wortDict[txt] = wortDict.get(txt, 0) + 1 + + + rows = len(values) + cols = len(values[0]) + transposedValues = [[0 for _ in range(rows)] for _ in range(cols)] + + for i in range(rows): + for j in range(cols): + transposedValues[j][i] = values[i][j] + + for i in transposedValues: + tmpResult={} + tmpResult["max"]=max(i) + tmpResult["min"]=min(i) + tmpResult["avg"]=round(sum(i)/len(i),2) + result.append(tmpResult) + + result.append(wortDict) + + #print(transposedValues) + print(result) + -result = analyze_iris() +analyze_iris() #print(result) -print("\n".join([str(i) for i in result])) \ No newline at end of file +#print("\n".join([str(i) for i in result])) \ No newline at end of file