Computer Science
Grade 5
20 min
2. Data Types and Visualization Techniques: Categorical, Numerical, and Time Series Data
Explore different data types and the appropriate visualization techniques for each, including categorical, numerical, and time series data.
Tutorial Preview
1
Introduction & Learning Objectives
Learning Objectives
Identify the three main data types: categorical, numerical, and time series.
Use `if/elif/else` statements to sort data based on its category or numerical value.
Use `for` loops to iterate through a list of data items one by one.
Write a Python program that counts items in different categories using a loop and conditionals.
Write a Python program that finds the highest or lowest number in a list of numerical data.
Explain how control structures help prepare data for making charts and graphs.
Ever wonder how your favorite game sorts players by score or shows your progress over a week? 🎮 Let's learn how Python code makes that happen!
In this lesson, we will explore three types of data: categorical, numerical, and time series. We will use Python'...
2
Key Concepts & Vocabulary
TermDefinitionExample
Categorical DataInformation that can be sorted into groups or categories. It uses labels, not numbers for math.A list of favorite ice cream flavors: ['Chocolate', 'Vanilla', 'Strawberry', 'Chocolate']
Numerical DataInformation that is a number and can be used for counting, measuring, or math.The number of points scored in a game: [120, 95, 250, 180]
Time Series DataInformation that is collected over a period of time, like every hour, day, or week.The number of steps you walked each day: [5000, 7200, 6100, 8000]
Control StructureA block of code that decides the order in which instructions are run. The two main types we will use are conditionals and loops.`if` statements and `for` loops are both control structures.
Conditional St...
3
Core Syntax & Patterns
Categorical Data Counting Pattern
for item in data_list:
if item == 'category_A':
count_A += 1
elif item == 'category_B':
count_B += 1
Use this pattern when you have a list of labels (categorical data) and you want to count how many of each label you have. This is the first step to making a bar chart.
Numerical Data Finder Pattern
max_value = data_list[0]
for number in data_list:
if number > max_value:
max_value = number
Use this pattern to find the biggest (or smallest) number in a list. This is great for finding a high score on a leaderboard or the warmest day of the month.
4 more steps in this tutorial
Sign up free to access the complete tutorial with worked examples and practice.
Sign Up Free to ContinueSample Practice Questions
Challenging
Given a list of daily website visitors (time series data) `visitors = [100, 120, 150, 130, 180, 160]`, which code snippet correctly finds the day with the highest number of visitors to highlight on a line graph?
A.`for v in visitors: if v > 150: print('Peak day')`
B.`peak = 0; for v in visitors: if v > peak: peak = v`
C.`peak = visitors[0]; for v in visitors: if v < peak: peak = v`
D.`print(visitors[4])`
Challenging
A program must decide whether to create a bar chart or a line graph. It uses this logic: `if len(data_points) < 5 and type(data_points[0]) == str: make_bar_chart() else: make_line_graph()`. What is this code deciding based on?
A.If the data is categorical (text) with few items, make a bar chart; otherwise, assume it's a time series for a line graph.
B.If the data has more than 5 points, it must be a line graph.
C.If the data is numerical, make a bar chart; otherwise, make a line graph.
D.It always makes a line graph unless the data is empty.
Challenging
A program uses a `for` loop to process two lists, `x_coords = [1, 2, 3, 4]` and `y_coords = [5, 8, 6, 9]`, to draw points on a graph. What kind of visualization is this loop creating, and what data types are being related?
A.bar chart relating categorical and numerical data.
B.line graph showing one set of time series data.
C.pie chart showing parts of a whole.
D.scatter plot relating two sets of numerical data.
Want to practice and check your answers?
Sign up to access all questions with instant feedback, explanations, and progress tracking.
Start Practicing Free