Q:

python function showing error, matrix, vectors, reading csv file

I have this code now:
def computeFinalGrades(grades):

# loading and reading the file
gradesCSV=pd.read_csv(grades)
print(gradesCSV)

# creating matrix only with the grades
matrixGrades=np.array(gradesCSV.iloc[0:8,2:])
print(matrixGrades)

# creating empty array
result_vector=[]

for array in matrixGrades:
    if -3 not in array: 
        array = array[~np.isnan(array)] # removing any NaN values
        if len(array) == 1:
            mean_result = array[0]
        else:
            min_value = min(array)
            mean_result = (sum(array)-min(array))/(len(array)-1)
            print(mean_result)
    else: #-3 is in the list
        mean_result = -3
    result_vector.append(mean_result)
print(result_vector)
 
gradesFinal=np.array(result_vector)        

return gradesFinal

computeFinalGrades('test.csv')

And in this line: mean_result = (sum(array)-min(array))/(len(array)-1) it should return a rounded number which is rounded with another function I have and import.
It keeps giving me an error, so have can I use my round-function? It works fine in another file with both float-number and a vector

A:

Here is an optional solution (a bit messy but simple (brute iterative force!) )
EDIT: after talking with the author of the question, i'm posting the full code that helped him solve the question.
import numpy as np

result_vector = []
full_array = np.array(a) # I don't think I understand what a is here
for array in matrixGrades:
    if -3 not in array:
        array = array[~np.isnan(array)]
        if len(array) == 1:
            grade = roundedGrade(array[0])
        else:
            grade = math.floor((sum(array)-min(array))/(len(array)-1))
            grade = roundGrade(grade)
    else: #-3 is in the list
        grade = -3
    result_vector.append(grade)
print(result_vector)

def roundGrade(grades):
       
    # possible grades
    Grade=np.array([-3,0,2,4,7,10,12])
    
    for i in range(len(grades)):
        index=(np.abs(Grade-grades[i])).argmin()
        gradeRounded = Grade[index]
        
    return gradeRounded

you can of course turn the list into a vector using np.array ...

