Exploring Two Columns in Data Sets, CSP U9L4 – Study Notes
offline

Source: Code.org CSP Activity Guide

Tags: cross tab, cross tabulation, scatter plot, two-column analysis, data visualization, CSP, AP Computer Science Principles, Code.org App Lab

Difficulty: Beginner to Intermediate | Prerequisites: Familiarity with single-column data analysis (histograms, bar charts), basic understanding of datasets and tables in Code.org App Lab.


Big Picture

Up to this point in CSP, you have been looking at one column of data at a time: counting how often values appear, finding averages, and building simple charts. This lesson takes the next step by asking what happens when you look at two columns together. That is where cross tabulations and scatter plots come in. They let you spot relationships, patterns, and trends that a single column could never reveal on its own. This skill is central to the AP CSP Explore Performance Task and to real data analysis.


TL;DR

A cross tab counts how often combinations of two categorical columns appear together, letting you compare groups at a glance. A scatter plot places two numerical columns on the x and y axes so you can see whether they move together. Both are tools for exploring relationships between two columns of data in a dataset.


Key Terms

Cross tabulation (cross tab)

A table that shows how frequently every combination of values from two columns occurs in a dataset. One column's values become the rows, the other's become the columns, and each cell holds a count (or a summary statistic like the mean).

In simple terms, it is a grid that answers "how many times does category A show up alongside category B?"

Scatter plot

A chart that places each row of data as a dot on a two-axis grid, with one numerical column on the x-axis and another on the y-axis.

Think of it as a dot map of your data: each dot is one record, and where it lands shows the relationship between two numbers.

Positive correlation (positive association)

A pattern in a scatter plot where increases in one variable tend to accompany increases in the other. The dots slope upward from left to right.

In simple terms, when one number goes up, the other tends to go up too.

Categorical data

Data that falls into named groups or labels rather than numerical values. Examples: part of speech (noun, verb, adjective), grade level (Freshman, Sophomore), favourite class (Art, History).

Think of it as data you would sort into buckets rather than plot on a number line.

Numerical data (quantitative data)

Data expressed as numbers that you can do arithmetic with. Examples: word length, median household income, percentage of college graduates.

In simple terms, if you can meaningfully take the average of it, it is numerical.

Range (of a dataset)

The difference between the largest and smallest values in a column. Often stated as "minimum to maximum" rather than as a single number.

Think of it as the full span your data covers, from lowest to highest.


Core Content: Cross Tabulations

What a Cross Tab Does

  • Takes two columns from a dataset and builds a summary grid

  • One column's distinct values become the row headers; the other's become the column headers

  • Each cell holds a count (how many rows match that combination) or a summary value (like the mean)

  • In Code.org App Lab, you generate this using the cross tab chart type

Example 1: Words Dataset (Length × Part of Speech)

  • Columns used: word length (numerical) and part of speech (categorical)

  • The cross tab showed length values as rows and parts of speech as columns

  • Each cell's number told how many words of that length belonged to that part of speech

  • Key findings from the data:

    • Nouns appeared most frequently overall

    • Nouns also tended to be the longest words on average

    • Conjunctions tended to be the shortest on average

    • The "typical" noun length was about 288 (identified by reading the colour that represents the average in Code.org's heat-map style chart)

Example 2: Favourite Classes Dataset (Grade × Favourite Class)

  • Columns used: grade level (categorical) and favourite class (categorical)

  • The cross tab showed grades as rows and class subjects as columns

  • Key findings from the data:

    • Seniors' most popular class was Computer Science (13 students)

    • Freshmen liked History the most (10 students)

    • Older students (Juniors and Seniors) showed more diversity in their class preferences than younger students

Reading a Cross Tab

  • Read across a row to compare one group's distribution across categories

  • Read down a column to compare how different groups relate to one category

  • Look for the largest cell values to spot the most common combinations

  • Look for colour intensity (in App Lab's heat-map view) to quickly identify highs and lows


Core Content: Scatter Plots

What a Scatter Plot Does

  • Plots each row of data as a single point on a two-axis chart

  • The x-axis represents one numerical column; the y-axis represents another

  • The overall shape of the dots reveals whether the two columns are related

  • Best suited to two numerical (quantitative) columns, not categorical ones

Example: US States Dataset (Income × College Graduates)

  • Columns used: median household income (x-axis) and percent of adult college graduates (y-axis)

  • Each dot represents one US state

  • Key findings:

    • Income ranged from roughly $42,000 to $79,000

    • The percentage of adults with a college degree ranged from 19.9% to 42.1%

    • A clear positive correlation was visible: states with a higher percentage of college graduates tended to have higher median household incomes

    • The dots sloped upward from lower-left to upper-right, confirming the positive association

Interpreting Scatter Plots

  • Positive correlation: dots trend upward left to right. As x increases, y tends to increase.

  • Negative correlation: dots trend downward left to right. As x increases, y tends to decrease.

  • No correlation: dots are scattered with no clear pattern.

  • Outliers: individual dots that sit far from the overall cluster and may deserve investigation.

  • Always state the range of each axis to give context for the spread of data.

  • Correlation does not prove causation. Saying "states with more graduates have higher incomes" describes a pattern; it does not prove that one causes the other.


Real-World Applications

Cross tabs are used constantly in market research and public health: a polling firm might cross-tabulate age group against voting preference, and an epidemiologist might cross-tabulate vaccination status against infection outcome. Scatter plots are a standard first step in economics, medicine, and engineering whenever someone wants to check whether two measurements move together, such as advertising spend against revenue, or dosage against patient response.


Common Misconceptions

  • Students often think a cross tab only works with two categorical columns. It can also pair a numerical column with a categorical one (as the Words dataset did with length and part of speech), using averages or sums in the cells instead of simple counts.

  • Students often assume that a strong scatter plot pattern means one variable causes the other. It does not. Correlation shows that two things move together; causation requires controlled experiments or much deeper analysis.

  • Students sometimes confuse the "average colour" in Code.org's cross tab heat map with the actual arithmetic mean. The colour represents a visual midpoint to help you estimate; you still need to calculate the real mean from the data if precision matters.

  • Students sometimes try to make a scatter plot from two categorical columns. Scatter plots require numerical data on both axes; for two categorical columns, a cross tab is the right tool.


Why It Matters / Exam Flags

⚠️ The AP CSP exam expects you to describe patterns and trends found in data. Being able to read a cross tab or scatter plot and state what relationship it shows (or does not show) is a directly tested skill.

⚠️ You will be asked to choose the right visualisation for a given pair of columns. Remember: two categorical columns or one categorical and one numerical calls for a cross tab; two numerical columns calls for a scatter plot.

⚠️ Correlation vs. causation is a recurring exam topic. Always state that a scatter plot shows a correlation, never that it proves a cause.

⚠️ Be prepared to identify the range of values on each axis and describe the direction of a trend (positive, negative, or none) in plain language.


Quick Self-Test

  1. True or False: A scatter plot is the best chart type for comparing two categorical columns.

  1. Fill in the blank: When dots in a scatter plot trend upward from left to right, the two variables have a ______ correlation.

  1. True or False: If a cross tab shows that nouns are longer on average than conjunctions, we can conclude that being a noun causes a word to be longer.

  1. Fill in the blank: In a cross tab, each cell typically contains a ______ or a summary statistic like the mean.

  1. True or False: A scatter plot showing that states with more college graduates have higher incomes proves that college causes higher income.

Answers: 1. False (use a cross tab). 2. Positive. 3. False (correlation, not causation). 4. Count. 5. False (correlation does not prove causation).


Practice Q&A

Q: You have a dataset with columns for "Colour" (red, blue, green) and "Shape" (circle, square, triangle). Which visualisation should you use to explore the relationship between these two columns, and why?

A: A cross tab, because both columns are categorical. A scatter plot requires two numerical columns.

Q: A scatter plot of hours studied (x-axis) vs. exam score (y-axis) shows dots trending upward from left to right. Describe the relationship and state one thing this pattern does not tell you.

A: There is a positive correlation: students who studied more hours tended to score higher. This pattern does not tell you that more study time caused higher scores, because other factors (prior knowledge, sleep, test difficulty) could be involved.

Q: In a cross tab of Grade (Freshman, Sophomore, Junior, Senior) and Favourite Subject, the cell for Senior / Computer Science shows the highest count. What does this tell you?

A: More seniors in the dataset chose Computer Science as their favourite subject than any other grade/subject combination. It tells you about popularity within this dataset, not about all students everywhere.

Q: A scatter plot of two variables shows dots scattered randomly with no upward or downward trend. What type of correlation does this represent?

A: No correlation. The two variables do not appear to have a linear relationship.

Q: Why is it important to state the range of each axis when describing a scatter plot?

A: The range gives context for the spread and scale of the data. Without it, someone reading your description would not know whether values are tightly clustered or widely spread, or what the actual minimum and maximum values are.


Connections to Other Topics

This connects to earlier CSP units on single-column analysis (bar charts, histograms) because cross tabs and scatter plots are the natural next step: you already know how to summarise one column, and now you are comparing two. It also ties directly into the data section of the AP CSP Explore Performance Task, where you must identify a pattern or trend in a dataset and explain what it reveals. The correlation vs. causation distinction introduced here comes back in broader discussions of data ethics and responsible data interpretation.


Related Terms / Search Tags

cross tabulation, cross tab, contingency table, two-way table, scatter plot, scatterplot, scatter diagram, x-y plot, correlation, positive correlation, negative correlation, no correlation, association, categorical data, quantitative data, numerical data, bivariate data, two-column analysis, data visualisation, Code.org App Lab, CSP Unit 9, AP Computer Science Principles, correlation vs causation, exploring two columns, data patterns, data trends, range of data