1
dataset=[]
f= open('auto-mpg-data.csv')
csv_f=csv.reader(f)
for row in csv_f:
    dataset.append(row)

#reading column
mpg=[]
for row in dataset:
    mpg.append(row[0])
print(mpg)

print(max(mpg))

this is the data. When I try to find the maximum value from this list it show 9 instead of 46.6. How can I get this value?

1 Answer 1

1

The problem is that the items of the list mpg are strings, so the result is true as '9' is greater than '46.6' when comparing strings. You should convert the items in the list mpg to float numbers first:

mpg = [float(row[0]) for row in dataset]
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.