Data Analysis Fundamentals · Data Foundations and Loading
21 cards
Labeled Data Structures
-
Quick check
A dataset holds one rainfall reading per date for a single station, and each reading must stay tied to its date. Which container fits, and why?
AA DataFrame, because dated readings need two labeled axes
A DataFrame carries row labels and column labels; one labeled variable does not need a second axis.
BA Series, because it is one-dimensional and labels every value
Right. A Series is a one-dimensional labeled array, so each reading stays attached to its date rather than to a slot.
CA plain NumPy array, because dates can be read back from position
A plain array has no index, so the dates would exist only as positions and any reordering could lose them.
3 / 21
-
Quick check
`pd.Series(0.0, index=['a','b','c','d','e'])` is evaluated. What comes back?
AA Series of five values, the scalar repeated across every label
Right. A scalar requires an index and is repeated to match it, so the five labels set the length of the result.
BOne value at label 'a', with the remaining four labels dropped
The supplied index determines the length, so every label receives the value rather than only the first.
CFive separate DataFrame columns, one named after each label
The constructor builds one Series; the labels become its index, not the columns of a table.
6 / 21
-
Quick check
Two Series go into a dictionary passed to `pd.DataFrame`. One is labeled `a,b`; the other is labeled `b,c`. Which row labels does the table get?
AOnly `b`, since a row must hold a value in both columns
Alignment does not restrict the result to shared labels; rows with one side absent are kept and marked missing.
B`a` and `b` alone, because the first Series fixes the labels
Later Series contribute their labels too, rather than being fitted into whatever the first input happened to have.
C`a`, `b` and `c`, the union of the two indexes
Right. A dictionary of Series is aligned by label, and the result uses the union of the indexes.
9 / 21
-
Keep your progress in the app
That’s 3 of 8 quick checks. In the app they stay answered, and every lesson remembers where you left off.
-
Quick check
You hold two named lists of measurements, one with four values and one with five. The table must keep all five observations and carry explicit row labels. What has to happen first?
AMake both columns the same length, then supply five row labels
Right. Column arrays must share one length, and an explicit index has to match that same length.
BBuild the table now and rely on the shorter list being padded out
A short column is not filled in for you; the mismatch is an error rather than something settled quietly.
CGive four row labels and let the longer list be cut down to fit
An index of the wrong length is no reason to throw away a real observation.
11 / 21
-
Quick check
Series `x` is labeled `a,b,c` and Series `y` is labeled `b,c,d`. What does `x + y` return?
AThree results paired first with first, with the labels dropped
Pairing by position ignores the labels, which is precisely the mistake alignment exists to prevent.
BResults at `a`, `b`, `c` and `d`, missing where only one side has a value
Right. The operation returns the union of the indexes, and a label absent from either side yields a missing result.
CResults at `b` and `c` only, since both sides must supply a number
Labels present on only one side are kept in the union rather than removed from the result.
14 / 21
-
Quick check
You need the dimensions of a table, and then the type held in each of its columns. Which pair of attributes answers that?
A`columns` for the dimensions, then `index` for the types
`columns` holds column labels and `index` holds row labels; neither reports a size or a type.
B`shape` for the dimensions, then `array` for the types
`array` returns the ExtensionArray behind a single Series and does not report a type per column.
C`shape` for the dimensions, then `dtypes` for the types
Right. `shape` reports the axis dimensions, and `dtypes` reports the dtype of every column.
16 / 21
-
Quick check
A table mixes text and numeric columns and carries meaningful labels, but an outside routine needs a plain NumPy array. What should you expect from `to_numpy()`?
ARow and column labels travel with the array, and no data is ever copied
Both labeled axes are omitted, and the conversion may copy data — most often when the shared dtype is `object`.
BOnly the labels survive; the cell values stay behind in the table
The values are exactly what the array carries; the labels are what does not come along.
CLabels are dropped and mixed columns may be coerced to a single dtype
Right. `to_numpy()` omits row and column labels and may coerce heterogeneous columns to a common NumPy dtype.
19 / 21
-
Quick check
Which statement matches how these structures actually behave?
AA Series carries two labeled axes, and `to_numpy()` keeps the row labels
A Series has one labeled axis, and the NumPy conversion omits both row and column labels.
BA DataFrame allows a different dtype per column, and Series operations match by label
Right. Per-column dtypes are the DataFrame's defining trait, and Series arithmetic aligns on index labels.
CA dictionary of Series lines values up by position, and `shape` returns the column names
A dictionary of Series is aligned by label, and `shape` reports axis dimensions rather than names.
21 / 21
-
8 quick checks · then the test
In the app, finishing the quick checks opens this lesson’s 10-question test, and the ones you miss come back exactly when you’re about to forget them.
The whole course, on your phone
Lessons you can read, audio you can listen to on the way to work, and practice that remembers what you got wrong.