-1

Code:

f = open("iris.txt", "r")

**#w = write("iris.txt","w") --** 

print(f.read()) 

Text File:

4.6,3.2,1.4,0.2,Iris-setosa
5.3,3.7,1.5,0.2,Iris-setosa
5.0,3.3,1.4,0.2,Iris-setosa
7.0,3.2,4.7,1.4,Iris-versicolor
6.4,3.2,4.5,1.5,Iris-versicolor
6.9,3.1,4.9,1.5,Iris-versicolor

Example:
I want Iris-setosa = 0 and Iris-versicolor = 1, and there are multiple of setosa and versicolor in a line.

Output:

4.6,3.2,1.4,0.2,0
5.3,3.7,1.5,0.2,0
5.0,3.3,1.4,0.2,0
7.0,3.2,4.7,1.4,1
6.4,3.2,4.5,1.5,1
6.9,3.1,4.9,1.5,1
Gino Mempin
  • 25,369
  • 29
  • 96
  • 135

1 Answers1

0

You should set the data into a pandas data frame and then use pd.get_dummies() on this column if you intend to create a classification model

Alistair
  • 589
  • 3
  • 11