jeudi 3 mai 2018

How is iris.data written in a CSV file?

Any idea how to write iris.data in a csv file? I want to replicate something like it but I'm not sure how to write this in a csv file to get the same array format. When I do:

iris = datasets.load_iris()
iris_X = iris.data
print(iris_X)

the print returns:

[[ 5.1  3.5  1.4  0.2]
 [ 4.9  3.   1.4  0.2]
 [ 4.7  3.2  1.3  0.2]
 [ 4.6  3.1  1.5  0.2]
 [ 5.   3.6  1.4  0.2]
 [ 5.4  3.9  1.7  0.4]
 [ 4.6  3.4  1.4  0.3]...
 ]

I tried adding it all in one column in my csv but it reads it as a string e.g:

X

5.1, 3.5, 1.3, 0.2

df = pd.read_csv("C:////knn.csv")
X = df['X'].values
print(X)

returns:

['5.1, 3.5, 1.3, 0.2']

Aucun commentaire:

Enregistrer un commentaire