Data Types in Data Science: Categorical, Numerical & Ordinal

Machine learning algorithms are fundamentally mathematical calculators. They perform linear transformations, matrix multiplications, and gradient calculations. However, real-world raw data is rarely purely mathematical—it comes in forms like product ratings, zip codes, salary figures, and user preferences.
Understanding data types is a prerequisite for effective data cleaning, exploratory data analysis (EDA), feature engineering, and selecting the correct machine learning algorithms.
Here is a comprehensive guide to understanding, identifying, and preprocessing data types in data science.

The Master Data Hierarchy

At the highest level, data is classified into two main buckets: Quantitative (Numerical) and Qualitative (Categorical).
                            ┌─────────────────────────┐
                            │     Data Types in       │
                            │      Data Science       │
                            └────────────┬────────────┘
                                         │
                 ┌───────────────────────┴───────────────────────┐
                 ▼                                               ▼
    ┌─────────────────────────┐                     ┌─────────────────────────┐
    │  Quantitative (Numeric) │                     │ Qualitative (Categorical)│
    └────────────┬────────────┘                     └────────────┬────────────┘
                 │                                               │
        ┌────────┴────────┐                             ┌────────┴────────┐
        ▼                 ▼                             ▼                 ▼
  ┌───────────┐     ┌───────────┐                 ┌───────────┐     ┌───────────┐
  │ Discrete  │     │ Continuous│                 │ Nominal   │     │ Ordinal   │
  └───────────┘     └───────────┘                 └───────────┘     └───────────┘

1. Quantitative (Numerical) Data

Quantitative data represents measurable quantities expressed as numbers. Standard mathematical operations like addition, subtraction, and averaging are meaningful on numerical data.

A. Discrete Data

Discrete data consists of distinct, countable integer values. It cannot be divided into smaller sub-parts or decimal fractions.
  • Characteristics: Countable, finite or countably infinite, whole numbers only.
  • Examples:
    • Number of customer support tickets submitted ($0, 1, 2, 3$).
    • Total items in an e-commerce cart.
    • Number of cars parked in a lot.
  • Python Representation: int64

B. Continuous Data

Continuous data represents measurements that can take on any real value within a given range. It can be broken down into smaller fractions or decimals depending on measurement precision.
  • Characteristics: Uncountable, infinitely granular measurements.
  • Examples:
    • Patient body temperature ($98.6^\circ\text{F}, 101.2^\circ\text{F}$).
    • House prices ($250,500.50).
    • Travel time between cities.
  • Python Representation: float64

2. Qualitative (Categorical) Data

Qualitative data represents labels, characteristics, or descriptions that divide data into groups. Direct mathematical calculations (like calculating a mathematical average) are not meaningful on raw categorical data.

A. Nominal Data

Nominal data consists of discrete categories with no inherent rank, order, or quantitative value. One category is not greater or smaller than another.
  • Characteristics: Pure labels; arbitrary order.
  • Examples:
    • Payment method (Credit Card, PayPal, Apple Pay).
    • Country of residence (USA, India, Germany).
    • Eye color (Blue, Brown, Green).
  • Python Representation: object or string

B. Ordinal Data

Ordinal data represents categories that have a clear, natural order or ranking, but the mathematical distance between the categories is non-uniform or unquantified.
  • Characteristics: Ranked labels; non-quantified intervals between ranks.
  • Examples:
    • Customer satisfaction survey ratings (Poor, Neutral, Good, Excellent).
    • Education level (High School, Bachelor's, Master's, PhD).
    • T-shirt sizes (S, M, L, XL).
  • Python Representation: category (ordered)

Summary Comparison Matrix

Data Type Subtype Math Operations Allowed? Example Machine Learning Encoding Needed?
Numerical Discrete Addition, Multiplication, Averages Number of employees No (Keep as integers)
Numerical Continuous All arithmetic, scaling, log transforms Temperature, Salary No (Apply feature scaling)
Categorical Nominal Equality checks ($=$, $\neq$) Car brand (Toyota, Ford) Yes (One-Hot Encoding)
Categorical Ordinal Comparison operators ($>$, $<$, $=$) Service rating (Low, High) Yes (Ordinal / Label Encoding)

How to Prepare Data Types for Machine Learning

Because machine learning models require numerical inputs, categorical features must be transformed into numerical representations through encoding techniques.

1. Handling Ordinal Data: Ordinal Encoding

Since ordinal categories have a meaningful order, map them directly to an ordered sequence of integers.
Python

import pandas as pd

df = pd.DataFrame({'education': ['High School', "Master's", "Bachelor's", 'PhD']})

# Map ordered integers manually
education_map = {'High School': 1, "Bachelor's": 2, "Master's": 3, 'PhD': 4}
df['education_encoded'] = df['education'].map(education_map)

2. Handling Nominal Data: One-Hot Encoding

Since nominal categories have no order, mapping them to $1, 2, 3$ would accidentally imply a false mathematical sequence (e.g., $3 > 1$). Instead, create binary indicator columns (dummy variables) for each category.
Python

# One-Hot Encoding using Pandas
df_nominal = pd.DataFrame({'color': ['Red', 'Blue', 'Green']})
df_encoded = pd.get_dummies(df_nominal, columns=['color'])
Original Column:           One-Hot Encoded Output:
  color                    color_Blue  color_Green  color_Red
  Red            ───►          0            0           1
  Blue                         1            0           0
  Green                        0            1           0

Key Takeaway

Always audit your dataset’s data types early during Exploratory Data Analysis (EDA). Treating ordinal features as nominal destroys valuable sequence information, while treating nominal data as numerical introduces false mathematical relationships into your machine learning models.

About Adi Status

Adi Satus is a passionate financial writer with a keen interest in the ever-evolving world of loans, insurance, technology, and cryptocurrency. With years of experience researching and writing on a broad range of financial topics, Hindi Me Gyaan aims to simplify complex concepts and make them accessible for readers. Whether you're looking to secure a loan, navigate the world of insurance, explore the latest tech trends, or understand the intricacies of cryptocurrency, Hindi Me Gyaan provides expert insights and practical advice to help you make informed decisions. Always staying updated with the latest developments, Hindi Me Gyaan is dedicated to bringing you the most relevant, timely, and useful information to guide you on your financial journey.

View all posts by Adi Status →

Leave a Reply

Your email address will not be published. Required fields are marked *