Skip to learning content

DATA SCIENCE PYTHON PLAYGROUND

Data Foundations · A little practice goes a long way.

← Inspect lessonsTINY TABLES · REAL PYTHON · YOUR PACE
Understanding values · I16 · 8 MIN

Find missing values

Locate gaps before summarising.

Exercises within this concept

  1. FollowFollow the techniqueCurrent exercise
  2. ChangeAdapt a requirement
  3. TransferChoose and combine

Understand the idea

isna flags missing cells True and present cells False. Missing means unknown or absent; it is different from zero.

Concept sketch: count missing cells per columnpricetip2NaNNaN14NaNcolumnmissingprice1tip2count missing cells per column
Illustration · not the exercise output

A small example

For [5, missing, 0, missing], isna() is [False, True, False, True]: 2 gaps out of 4, or 50%.

Follow the code

Apply the idea to the supplied table. Read from top to bottom; the final line displays the result.

df.isna().sum()

What each part does

df.isna()
True at missing cells
.sum()
add down each column
None / NaN
missing-value representations

Your inputs

The editable setup on the right creates df. Run executes the setup and your work from top to bottom.

Messy café orders · 8 synthetic rows
orderdrinksizepricetipdate
101" latte "LARGE6.2012026-06-01
102TEAsmall3.100.52026-06-02
103" mocha "LARGEoopsNonenot a date
104LatteSmallNone0.82026-06-04
104LatteSmallNone0.82026-06-04
105"tea "SMALL4.200.62026-06-05
106ESPRESSOsmall2.500.22026-06-06
107" mocha"large6.801.52026-06-07

Your task · Follow

  1. Using df, return the number of missing values in every column.
  2. Use: isna().
Hint

isna makes the missing mask; sum counts True values down each column.

Reveal solution

One way to do it. Keep any supplied setup in the editor and use this in the Your work section.

df.isna().sum()
Your task · Follow
  1. Using df, return the number of missing values in every column.
  2. Use: isna().

Tab: indent · Shift+Tab: outdent · Esc, then Tab: leave editor

Edit Python. Control or Command plus Enter runs it. Tab indents by four spaces. Shift plus Tab outdents. Press Escape, then Tab or Shift plus Tab to leave the editor.

Each run executes all editor code in a fresh Python session. Display a value by leaving it on the final line.

Python starts when you open a lesson.

Output

Run your code to see what Python returns.