Working with DataFrames — flashcards
One card per lesson — 5 in this module. Recall the key points, then check. 5 cards. Click a card to flip, or use the arrow keys and space bar.
Loading data — what are the key points?
Read identifier columns as str to preserve leading zeros · parse_dates at load time avoids converting later · sheet_name=None reads every Excel sheet into a dictionary Read the lesson
Inspecting a DataFrame — what are the key points?
Run head, shape, info and describe on every new dataset · dtype object on a date column means it is text · value_counts() exposes inconsistent category labels Read the lesson
Selecting and renaming columns — what are the key points?
Single brackets give a Series; double brackets give a DataFrame · df.columns.str.strip().str.lower() fixes most messy headers at once · Most methods return a new DataFrame — assign the result Read the lesson
Filtering rows — what are the key points?
Use & and | in pandas, never and / or · Parenthesise each condition — & binds tighter than comparisons · loc is label-based and slice-inclusive; iloc is positional and slice-exclusive Read the lesson
Creating and modifying columns — what are the key points?
np.where for two outcomes, np.select for several · apply runs per row and is slow — vectorise where possible · Add .copy() after filtering before assigning, or use df.loc directly Read the lesson