i am trying to put the iris data set into a list however when i try to read the lines in the file it doesn't separate each value and instead puts it in 1 string. how do i fix this so that it opens and separate the data? some of the data:
sepal_length,sepal_width,petal_length,petal_width,species
5.1,3.5,1.4,0.2,setosa
4.9,3.0,1.4,0.2,setosa
4.7,3.2,1.3,0.2,setosa
4.6,3.1,1.5,0.2,setosa
5.0,3.6,1.4,0.2,setosa
5.4,3.9,1.7,0.4,setosa
4.6,3.4,1.4,0.3,setosa
code:
import csv
with open("iris.csv", "r") as csv_iris:
read = csv.reader(csv_iris, delimiter = ",")
for line in csv_iris:
print(line[0])
output:
s
5
4
4
4
5
5
4
what output should be:
sepal_length
5.1
4.9
4.7
4.6
5.0
5.4