i have a python script that read from csv file and append the requested columns into 2 empty list. after that i need to extract the minimum and maximum value of the columns extracted.
i wrote this code but it seems not working be cause the result is empty .
import csv
mydelimeter = csv.excel()
mydelimeter.delimiter=";"
myfile = open("C:/Users/test/Documents/R_projects/homework/rdu-weather-history.csv")
myfile.readline()
myreader=csv.reader(myfile,mydelimeter)
mywind,mydate=[],[]
minTemp, maxTemp = [],[]
for row in myreader:
print(row[1],row[2])
minTemp.append(row[1])
maxTemp.append(row[2])
print ("min value element : ", min(minTemp))
print ("max value element : ", min(maxTemp))
You can Use Pandas Where You can load the data into DataFrames and They have inbuilt functions such as Sum,Max,Min,AVG etc.
import pandas as pd
df=pd.read_csv('Name.csv')
#FINDING MAX AND MIN
p=df['ColumnName'].max()
q=df['ColumnName'].min()
print(q)
Thats it You will find the Min value in the Specified column.
This might help
import csv
with open('C:/Users/test/Documents/R_projects/homework/rdu-weather-history.csv', "r") as csvfile:
data = csv.reader(csvfile, delimiter=';')
minVal, maxVal = [], []
for i in data:
minVal.append(i[1])
maxVal.append(i[2])
print min(minVal)
print max(maxVal)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With