Data Analysis Fundamentals · Data Foundations and Loading
21 cards
File and Object I/O
-
Quick check
A file is pipe-delimited and its first line is already data, not column names. Which pair of settings describes that layout?
A`sep='|'` together with `header=None` and explicit `names`
Right. The delimiter is declared, the absent header row is stated, and explicit names replace the ones the file never had.
B`index_col='|'` with `header=0` and inferred names
`index_col` chooses which column becomes the row labels; it does not declare the field separator.
C`sep='|'` on its own, letting the first line supply the column names
Leaving `header` at its default treats that first data line as column names, so a real row is lost.
3 / 21
-
Quick check
Which pair of `read_csv()` settings restricts the columns that are parsed and requests how they are represented?
A`header` for the selection and `quotechar` for the representation
`header` says which row holds the names, and `quotechar` concerns how quoted fields are read.
B`na_values` for the selection and `encoding` for the representation
`na_values` adds missing markers and `encoding` governs decoding; neither selects columns or sets types.
C`usecols` for the column selection and `dtype` for the representation
Right. `usecols` limits which columns are parsed, and `dtype` maps the object or named columns to requested types.
5 / 21
-
Quick check
A pipe-delimited file has no header row, uses `NA?` as its only missing marker, and holds an identifier that must stay text. Only three of its columns are needed. Which design meets all of it?
ARead it with the defaults, then rename the columns and cast everything to floats
Casting to floats destroys the text identifier, and renaming afterwards cannot recover what parsing already changed.
BDeclare delimiter, absent header, names, projection, text type and markers
Right. Delimiter, absent header, explicit names, `usecols`, a text dtype and `na_values` with `keep_default_na=False` cover every constraint.
CSet `header=0`, keep every column, and rely on the default set of missing markers
`header=0` consumes a real data row as names, and the default markers do not match a file whose only marker is `NA?`.
8 / 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
A table must survive a JSON round trip with its dtypes and its index name intact. Which approach works?
AWrite with `orient='records'` and reconstruct the index name from it afterwards
Records omits index labels entirely, so there is no index name left in the file to recover.
BUse `orient='table'` on the write and supply the same orientation on the read
Right. Table orientation follows JSON Table Schema and preserves dtypes and index names, and a non-default orientation must be supplied on the read too.
CWrite with `orient='columns'` and then read it back with `orient='split'`
A document written in one orientation cannot be interpreted by a reader expecting a different one.
11 / 21
-
Quick check
A records-orientation export is written with `lines=True`, and some cells were missing. What does the file look like?
AOne record per line, with missing cells written as JSON `null`
Right. `lines=True` emits one record per line, and `NaN`, `NaT` and `None` are all written as JSON `null`.
BOne record per line, with missing cells left out of their objects
The values are represented rather than omitted, so the record keeps its full set of keys.
CA single array on one line, keeping the missing cells as `NaN` text
`lines=True` is precisely what replaces the single-array layout, and `NaN` is not valid JSON.
13 / 21
-
Quick check
`read_excel(..., sheet_name=['North', 3])` is called on a four-sheet workbook. What comes back?
AOne table made by stacking every sheet in the workbook
Requesting several sheets does not append them; nothing in the call combines the two tables.
BOnly the first sheet, because a list is ignored by `sheet_name`
A list is one of the accepted forms for `sheet_name`; the default of zero applies only when it is omitted.
CA dictionary holding the named sheet and the sheet at position three
Right. A list of names or positions requests those sheets and returns them in a dictionary.
16 / 21
-
Quick check
A DataFrame with a custom index goes to Parquet for a non-pandas consumer that expects exactly the named data columns. What should the writer do?
AWrite with `index=False`, accepting that the custom index will not round-trip
Right. An explicit `index=False` omits the index field, and the documented cost is that the custom index is not recovered.
BWrite with `index=True`, so that no extra index field reaches the consumer
`index=True` is the setting that writes the index into the file, which is the field the consumer rejects.
CLeave `index` implicit and rely on both engines producing exactly the same schema
Index serialization differs by engine unless `index` is explicit, so an implicit setting cannot guarantee the schema.
19 / 21
-
Quick check
Which statement matches how these readers and writers behave?
A`orient='records'` is the JSON layout that preserves index labels
Records is precisely the orientation that omits index labels; `table` is the one that carries that metadata.
B`sheet_name` defaults to `None`, so every sheet is read at once
The default is zero, so only the first sheet is read; `None` is what requests all of them.
C`read_parquet(columns=[...])` reads only the columns you list
Right. The read-side projection materializes only the selected columns of the file.
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.