lundi 15 novembre 2021

I'm new to coding, after finding the maximum value float in the csv file, I want to print the whole row, which includes strings. I'm using python

import csv
with open('Prenoms.csv', 'r') as f:              # open file variable f
   reader = csv.reader(f)                       # read file
   next(reader)                                   # skip the first line
   answer = max(float(column[3].replace(',', '')) for column in reader)
print(answer)                                     # show max value                                  
#print("hi")                                      # Debugging line of code (works)
float_value = answer
string_value = str(float_value)                  # translate from float to string
f = open("Prenoms.csv","r")                       # Open file for read only

c = csv.reader(f, delimiter=',')                    # Read the file using the
                                                    # assigned delimiter
 while row in c: 
     if answer == row[3]:
        print(row)
     else:
         print("hi i'm here!")                    # while loop checks unlit list ends                    
for row in c:                                      # for loop checks for 11629 times
    if answer == row[3]:                            # if conditional to check if the 
                                                #row contains the desired float (max)
         print(row)                                 # Doesn't print but no errors are shown
        print("Hello World")                        # This is a debugging line of
                                                    # code but it doesn't print
f.close()
#print(row)                                         # This prints wrong row
#print("Hello World")                               # Debugging line of code (works)

Aucun commentaire:

Enregistrer un commentaire