Value Error: could not convert string to float: 'good'

Value Error: could not convert string to float: 'good'

我正在尝试用训练数据集拟合决策树模型。但是发现这个错误

credit_df=pd.read_csv('credit.csv')
credit_df.head()

[! dataframe]1

X = credit_df.drop("default" , axis=1)
Y=credit_df.pop("default")
from sklearn.model_selection import train_test_split

X_train, X_test, train_labels, test_labels = train_test_split(X, y, test_size=.30, random_state=1)

dt_model = DecisionTreeClassifier(criterion = 'gini' )
dt_model.fit(X_train, train_labels)

我尝试了下面的代码,现在错误已修复。有一些对象数据类型,我将它们转换为分类值

for feature in credit_df.columns: 
    if credit_df[feature].dtype == 'object': 
        credit_df[feature] = pd.Categorical(credit_df[feature]).codes