# How to encode Income Type Ordinal Data into numbers?

I am doing a mini project on Credit card Approval Prediction. The Dataset I have taken is from Kaggle: https://www.kaggle.com/datasets/rikdifos/credit-card-approval-prediction

Problem: I want to encode this ordinal column:

ord_col = ['Income Type', 'Education', 'Housing Type', 'Occupation Type']

new_data['Income Type'].value_counts()
OP:
Working                 18819
Commercial associate     8490
Pensioner                6152
State servant            2985
Student                    11
Name: Income Type, dtype: int64

new_data['Education'].value_counts()
OP:
Secondary / secondary special    24777
Higher education                  9864
Incomplete higher                 1410
Lower secondary                    374
Name: Education, dtype: int64

new_data['Housing Type'].value_counts()
House / apartment      32548
With parents            1776
Municipal apartment     1128
Rented apartment         575
Office apartment         262
Co-op apartment          168
Name: Housing Type, dtype: int64

new_data['Occupation Type'].value_counts()
Unknown                  11323
Laborers                  6211
Core staff                3591
Sales staff               3485
Managers                  3012
Drivers                   2138
High skill tech staff     1383
Accountants               1241
Medicine staff            1207
Cooking staff              655
Security staff             592
Cleaning staff             551
Private service staff      344
Low-skill Laborers         175
Waiters/barmen staff       174
Secretaries                151
HR staff                    85
Realty agents               79
IT staff                    60
Name: Occupation Type, dtype: int64


You can use the pd.Series.map() to map your ordinal data of Income Type to numbers.

Documentation for Series.map()

Here is a step by step guide

1. Create a dictionary to map the Income Types to different numbers.
income_types_enc = {
'Working': 1,
'Commercial associate': 2,
'Pensioner': 3,
'State servant': 4,
'Student': 5
}

1. Create a new Column with the encoded Income Types
df['Encoded Income Type'] = df['Income Type'].map(income_types_enc)


I hope this solves your issue😀. Have a good day!

I usually go with setting the column type to 'category' and assigning category codes from there to the column like this:

df = pd.read_csv("./application_record.csv")
df["NAME_INCOME_TYPE"] = df["NAME_INCOME_TYPE"].astype("category").cat.codes


And you can repeat the same procedure for the other categorical columns.