11 Aralık 2022 Pazar

Converting numerical value to category

Sometimes we may need to numerical values (integers) to categorical values (object/strings) because there is no point in running a regression as if thesee numbers represent a mathematical value or have a ranking (such as sector codes in a bank loan data). Here's how it's done:

Code:

# There columns should not be integers, but objects.
# These are Primary_Loan_Digit and Code_Franchise
data_train['Primary_Loan_Digit'] = pd.Categorical(data_train.Primary_Loan_Digit)
data_train['Code_Franchise'] = pd.Categorical(data_train.Code_Franchise)
data_test['Primary_Loan_Digit'] = pd.Categorical(data_test.Primary_Loan_Digit)
data_test['Code_Franchise'] = pd.Categorical(data_test.Code_Franchise)
data_train.dtypes

Türkçe:

Sayısal veriyi kategorik veriye dönüştürmek

Hiç yorum yok:

Yorum Gönder