mardi 21 juin 2016

Minimum and maximum on array matrix, python

I need to take the max and min of ages by country and position, but I get the error

'numpy.int32' object is not iterable

Here's the csv file. The specific case is when reporte is 4. https://mega.nz/#!eURwDTCI!clYmejGQC4cBGc7d7RBhpaRwtuE_D9XhDWd4W_udEs0

data=[]

with open("wc2014_finals.csv", "r") as f:
    for line in f:
        data.append(line.rstrip('n'))

import numpy as np
country = ["Brazil", "Chile", "Columbia", "Ecuador", "Argentina", "Costa Rica", "Mexico", "USA", "Belgium", "France", "Germany", "Netherlands","Switzerland", "Greece", "Nigeria", "Algeria"]
position=["Defender","Forward","Goalkeeper","Midfielder"]
#print(country)
#print(position)
token=[]
est=np.zeros((4,16), int)
ages=np.zeros((4,16), int)
cages=np.zeros((4,16), int)
height=np.zeros((4,16), int)
cheight=np.zeros((4,16), int)
weight=np.zeros((4,16), int)
cweight=np.zeros((4,16), int)

for elements in data:
    token = elements.split(",")
    for i in range(0, len(position)):
        if position[i] == token[2]:
            for j in range(0, len(country)):
                if country[j] == (token[-4]):
                    est[i, j] += (int(token[-2]))
                    ages[i, j] += (int(token[7]))
                    height[i, j] += (int(token[8]))
                    cheight[i, j] += 1
                    weight[i, j] += (int(token[9]))
                    cweight[i, j] += 1

height=height/100
promheight=(height/cheight)
#print(promheight)
promweight=(weight/cweight)
#print(promweight)

imc=(promweight)/((promheight)**2)
#print(imc)
print(ages)

while True:
    opcion = int(input("Elija 1 para reportes o 2 para salir: "))
    if opcion == 1:
        reporte = int(input("Ingrese 1 para reporte por PAIS, 2 para reporte por PAIS Y POSICION, 3 para reporte por IMC o 4 para reporte de EDAD : "))
        if (reporte == 1):
            p=input("Ingrese un pais de la lista de paises mencionada: ")
            for i in range(len(country)):
                if p == country[i]:
                    print("Goles:", est[:, country.index(p)].sum())
        elif (reporte == 2):
            p = input("Ingrese un pais de la lista de paises mencionada: ")
            po = input("Ingrese una posicion de las lista de posiciones mencionada: ")
            print("Goles: ", est[position.index(po), country.index(p)])
        elif (reporte == 3):
            p = input("Ingrese un pais de la lista de paises mencionada: ")
            po = input("Ingrese una posicion de las lista de posiciones mencionada: ")
            print("IMC: ", np.around(imc[position.index(po), country.index(p)], decimals = 2))
        elif (reporte == 4):
            p = input("Ingrese un pais de la lista de paises mencionada: ")
            po = input("Ingrese una posicion de las lista de posiciones mencionada: ")
            print("Edad mínima: ",(ages[position.index(po), country.index(p)])  )
            print("Edad máxima: ", )

    if opcion == 2:
        print("Proceso finalizado")
        break

Aucun commentaire:

Enregistrer un commentaire