Selecting, cleaning and transforming

Selecting with loc, iloc and masks, finding and handling missing values, and creating and recoding columns.

About 6 hours of study

Learning objectives

Lessons

  1. 1

    Selecting rows and columns: loc, iloc and masks Intermediate

    Choosing parts of a DataFrame by label with loc, by position with iloc, and by condition with boolean masks combined with &, | and ~, plus assigning values through a selection.

  2. 2

    Missing data: finding, dropping and filling Intermediate

    How pandas marks missing values with NaN and None, counting them with isna, how statistics skip them, and the two ways to deal with them: dropping rows with dropna or filling with fillna, ffill and bfill.

  3. 3

    Transforming columns Intermediate

    Creating and changing columns: arithmetic between columns, assign, map with a dictionary, apply with a function, astype, rename and drop, and binning numbers into categories with cut.

Module practice

Module quiz

1. df.loc[2:4] with integer labels includes…
2. Which combines two conditions in a filter?
3. What does df.isna().sum() give?
4. dropna(subset=['age']) removes…
5. What does pd.cut do?
6. Why prefer df.loc[mask, 'col'] = v to df[mask]['col'] = v?

‹ pandas foundationsSummarising and reshaping ›