Lesson 3 · Probability and Statistics in python
Understanding Data Types: Categorical, Numerical, Continuous, and Discrete Explained
In this lesson, you will learn to recognize different types of data used in statistics and data science. We will focus on four key data types: Categorical…
- CourseProbability and Statistics in python
- Lesson3 of 35
- Video7 min
- FormatJupyter notebook · 12 code cells
What you'll learn
Data
No separate download needed — the notebook creates or downloads everything it uses.
📓 Full notebook
Download .ipynbWelcome to Probability and Statistics: Types of Data#
In this lesson, you will learn to recognize different types of data used in statistics and data science.
We will focus on four key data types:
- Categorical (qualitative)
- Numerical (quantitative)
- Discrete
- Continuous
Let's get started!
# Let us start by importing the libraries we will use
import warnings
warnings.filterwarnings("ignore")
import numpy as np
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
# These tools help you load, analyze, and display data
What are Types of Data?#
Understanding data types helps you choose the right tool or graph.
- Categorical data: Labels or categories (like colors, city names)
- Numerical data: Numbers you can add or average
- Discrete: Whole numbers you count (like people in a room)
- Continuous: Any value in a range (like height or weight)
You will see real examples soon.
# Data setup
# Let us load the Titanic dataset. It has both categorical and numerical data.
titanic = sns.load_dataset("titanic")
print("Rows, Columns:", titanic.shape)
titanic.head()
Spotting Categorical Data#
Categorical data is made up of non-numeric labels.
Examples in Titanic: sex, embarked, class, who, deck.
You CANNOT do math on these, but you can count or compare groups.
# Let us check which columns are categorical
categorical_cols = titanic.select_dtypes(include=["object", "category"]).columns
print("Categorical columns:", list(categorical_cols))
Spotting Numerical Data#
Numerical data are values you can count or measure.
Examples in Titanic: age, fare, sibsp (siblings/spouses), parch (parents/children).
You CAN do math on these values.
# Let us see which columns are numerical
numerical_cols = titanic.select_dtypes(include=["int", "float"]).columns
print("Numerical columns:", list(numerical_cols))
# Let us peek at the data types for each column
titanic.dtypes
Discrete vs Continuous Data#
Discrete data: Whole numbers, countable items (1, 2, 3, ...). Continuous data: Any value in a range, like 2.51 or 180.6.
In Titanic:
sibsp,parchare discrete (number of siblings, number of children).age,fareare continuous (age in years, fare in money).
# Let us count the unique values for 'sibsp' and 'parch'
print("sibsp unique values:", titanic['sibsp'].unique())
print("parch unique values:", titanic['parch'].unique())
# Let us check some age and fare values
print("Age samples:", titanic['age'].dropna().unique()[:10])
print("Fare samples:", titanic['fare'].unique()[:10])
Quick Visualization: Categorical Example#
Let us see how many people traveled in each class (pclass).
This is a bar plot for categorical data.
# Plotting a bar chart for passenger class (categorical)
sns.countplot(data=titanic, x='pclass')
plt.title('Passenger Count by Class')
plt.xlabel('Class')
plt.ylabel('Number of Passengers')
plt.show()
Quick Visualization: Numerical Example#
Now, let us look at the ages of passengers.
A histogram is great to plot continuous numbers.
# Plotting a histogram for passenger age (numerical, continuous)
sns.histplot(data=titanic, x='age', bins=30, kde=True)
plt.title('Distribution of Passenger Ages')
plt.xlabel('Age')
plt.ylabel('Frequency')
plt.show()
# Practice: What type of data is 'sex'?
answer = input("Is 'sex' categorical, discrete, or continuous? ")
if answer.lower() == "categorical":
print("Correct! 'sex' is categorical.")
else:
print("Try again: Categorical means labels like male or female.")
# Visual summary: Counts per embarkation port (categorical)
sns.countplot(data=titanic, x='embarked')
plt.title('Passengers by Embarkation Port')
plt.xlabel('Embarked Port')
plt.ylabel('Number of Passengers')
plt.show()
# Now, let us see how fare (continuous number) looks by class (categorical group)
sns.boxplot(data=titanic, x='pclass', y='fare')
plt.title('Fare by Passenger Class')
plt.xlabel('Class')
plt.ylabel('Fare')
plt.show()
# Show missing values for categorical and numerical columns
print(titanic[categorical_cols].isnull().sum())
print(titanic[numerical_cols].isnull().sum())
Wrap-up: Types of Data#
- Categorical: Labels like male, female, port
- Discrete: Counted numbers like siblings, children
- Continuous: Measured values like age, fare
Understanding these types will help you explore and analyze any dataset.
Try it yourself!#
- Use
sns.histplotto plot another continuous variable. - Try counting a different categorical group with
sns.countplot.
Pause and type your own examples.
If you learned something new, please like and subscribe for more!
Found this useful?
All lessons, notebooks and datasets here are free. If they helped you, a coffee keeps new lessons coming.



