Each run starts with fresh data. Download any exported files before another run. Your written answers and code drafts are saved on this device; export your work to keep a backup.
M03C01 · Explore · predict · practice
One column, with labels
The setup imports pandas using the short name pd. A Series is a one-dimensional collection of values with an index: labels attached to those values. Without an explicit index, pandas supplies labels starting at 0. A Series also has a dtype describing how its values are stored.
The Series contains three study-hour values and is named Study_Hours. Its default index is still 0, 1, 2.
Compare your explanations
Read. pd is the alias for the pandas package created by import pandas as pd in the setup.
Predict. 0, 1, and 2.
Explain. No. It labels each score; it is not an additional measurement in the Series.
One quick check
A Series is best described as:
What you should be able to explain. I can distinguish Series values, index labels, and the Series name.
M03C02 · Explore · predict · practice
Choose labels or positions explicitly
You can supply meaningful labels, such as student IDs, as the Series index. loc selects an index label; iloc selects an integer position. These can identify the same value, but they ask different questions. Using them explicitly avoids confusing a number used as a label with a position.
S003 has score 91. Position 0 contains S001's score, 88.
Compare your explanations
Read. scores.loc["S002"] asks for the label S002. scores.iloc[1] asks for position 1, the second value.
Predict. 72 and 72.
Explain. No. Sorting can change positions. The S002 label still identifies that student's score.
One quick check
Which selector is explicitly positional?
What you should be able to explain. I can select a Series value by label or by position.
M03C03 · Explore · predict · practice
Do arithmetic on a whole Series
Pandas can apply an arithmetic operation to all values at once. This is called a vectorized operation. scores + 2 creates a new result; it does not replace scores unless you assign the result back. clip() can enforce an upper or lower boundary when that is the stated rule.
The new scores are 93, 77, and 100. Clipping applies the stated maximum; it should not be used to hide unexplained invalid source data.
Compare your explanations
Read. It adds 2 to every value in the Series, keeping the index labels.
Predict. The new result is 101. The original scores value remains 99.
Explain. It exceeds the permitted range. If the rule allows bonus marks but caps scores at 100, clipping can apply that explicit rule.
One quick check
What does result = scores + 2 normally do?
What you should be able to explain. I can calculate a new labeled column without writing a loop.
M03C04 · Explore · predict · practice
Labels control Series alignment
When combining two Series, pandas matches index labels, even when their order differs. It does not simply pair the first value in one Series with the first value in the other. A label missing from one side normally produces a missing result for arithmetic.