Home > Mobile >  max in multi-dimensional list python from a file
max in multi-dimensional list python from a file

Time:06-13

hey please I need to know soon as possible how to get the max from a file .csv in the whole file and I'm just beginner at python I learned yesterday I search a lot ten I find this code but it's not useful for me:

import csv #librairies
import math
with open('Classeur8.csv') as csvfile:
    reader=csv.reader(csvfile,delimiter=";")
    linecount=0
    id_max=0
    temp_max= -math.inf
    for row in reader:
        if linecount==0:
            print(f'column names are {",".join(row)}')
            linecount  =1
        else:
            print(f'our id is {row[0]} and temperature is {row[1]} ')
            linecount  =1
            if float(row[1]) > temp_max:
                id_max,temp_max=row[0],float(row[1])
    print(f'processed lines:{linecount}')
    print(f'max_id:{id_max} and max_temperature:{temp_max}')

Classeur8.csv

id;temperature
2;23
3;33
4;43
5;53
6;63

CodePudding user response:

You can use Pandas: This has inbuilt functions such as Sum, Max, Min, AVG, etc.

import pandas as pd

df=pd.read_csv(Classeur8.csv)


#FINDING MAX
p=df['temperature'].max()


print(p)
  • Related