changed to transponded

main
Ermis Wieger 2025-01-29 18:39:22 +01:00
parent c2e0f2909e
commit 923b007054
1 changed files with 29 additions and 12 deletions

37
main.py
View File

@ -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)
values.append(tmpValues)
wortDict[txt] = wortDict.get(txt, 0) + 1
result.append(wortDict)
return result
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]))
#print("\n".join([str(i) for i in result]))