File size: 510 Bytes
47d08e5 |
1 2 3 4 5 6 7 8 9 10 11 12 13 |
from sklearn import preprocessing
class FuncToNumber:
def ToNumber(df):
# transform non-numerical labels to numerical labels
#Name,Sex,Age,SibSp,Parch,Ticket,Fare,Cabin,Embarked
le = preprocessing.LabelEncoder()
df["Sex"] = le.fit_transform(df["Sex"])
df["Age"] = le.fit_transform(df["Age"])
df["Ticket"] = le.fit_transform(df["Ticket"])
df["Fare"] = le.fit_transform(df["Fare"])
df["Cabin"] = le.fit_transform(df["Cabin"])
return df |