Data science

Stage 1 · Lesson 4 of 7

Selecting columns and filtering rows

Python for data: NumPy and pandas

Most questions start by narrowing the data to the rows and columns that matter, such as paid orders from the last quarter. In you use loc with a boolean mask, a series of True and False values, and a list of column names. In dplyr you use filter and select.

Combine conditions with and, or and not, and learn helpers for ranges, lists of allowed values and text patterns. Write down in plain words which your defines, because every number you report later describes only that group.

A filter on a column with missing values also drops those rows silently in either language.

Common trapThe trap is, in pandas, writing and instead of & or forgetting the brackets around each condition, which raises an error or, worse, filters on the wrong thing.

A question to check yourself, an AI practice session and 1 cheat sheet entry come with the full roadmap. Unlock

Resources for this stage

Start with· follow one of these

  • CoursePaid
    Grokking Python Fundamentals

    Design Gurus · Beginner · $50

    Solid Python basics first: data types, collections, functions and files, the ground pandas stands on

  • CourseFree
    Kaggle Learn

    Kaggle · Beginner

    Free: the Python and Pandas courses, short lessons with exercises that run in the browser

Practise

  • Pick one dataset on a topic you care about and repeat every operation in this stage on it

Keep handy

  • The indexing, merging and reshaping pages answer most "how do I" questions

  • The absolute beginners guide, then the reference when an array does something unexpected

Also worth your time

Mark this stage as not done?