changed to transponded
parent
c2e0f2909e
commit
923b007054
41
main.py
41
main.py
|
|
@ -2,28 +2,45 @@ import csv
|
||||||
|
|
||||||
|
|
||||||
def analyze_iris():
|
def analyze_iris():
|
||||||
|
|
||||||
result=[]
|
result=[]
|
||||||
wortDict={}
|
wortDict={}
|
||||||
|
values=[]
|
||||||
with open("Iris.csv", mode='r', encoding='utf-8') as file:
|
with open("Iris.csv", mode='r', encoding='utf-8') as file:
|
||||||
|
|
||||||
reader = csv.reader(file)
|
reader = csv.reader(file)
|
||||||
next(reader, None) # skip the header if present
|
next(reader, None) # skip the header if present
|
||||||
for row in reader:
|
for row in reader:
|
||||||
txt=row[5]
|
txt=row[5]
|
||||||
tmpValues=row[1:5] # slice row array id
|
tmpValues=row[1:5] # slice row array id
|
||||||
tmpValues=[float(x) for x in tmpValues] # Convert from string to float array - typecasting
|
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(result)
|
||||||
print("\n".join([str(i) for i in result]))
|
#print("\n".join([str(i) for i in result]))
|
||||||
Loading…
Reference in New Issue