

# https://www.globalsino.com/ICs/page4853.html
# Read values in a csv file for calculation

# key = column name

from csv import DictReader
from typing import List, Dict

csv_file = open(r'C:\GlobalSino\images\TestImages\Excel\dataonly.csv', encoding = 'utf8')

# Build dictionaries
csv_reader = DictReader(csv_file)

MyTable: List[Dict[str, float]] = []

# Read each row into a dictionary (the dictionary name is "row", the key is the column)
for row in csv_reader:
    # Build a new dictionary "MyFloat_Row"
    MyFloat_Row: Dict[str, float] = {}
    for column in row:
        MyFloat_Row[column] = float(row[column])
        MyTable.append(MyFloat_Row)
print(MyTable)


# Read numbers as numbers, thenthe numbers can be carried out for calculations.
City_all: float = 0.00
for row in MyTable:
    City_all += row["City"]
print("City mean:" + str(City_all/len(MyTable)))

csv_file.close()
    
