0Pricing
Data Science Academy · Lesson

Drop vs Fill: Choosing Wisely

When to remove and when to impute.

Drop vs Fill: Choosing Wisely is a free Data Science Academy lesson on CoddyKit — lesson 2 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Data Science Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Two Roads at a Gap

When you meet missing data, you face one big choice: drop the affected rows, or fill them in. The right road depends on how much you lose either way. 🛣️

Dropping Rows

The method dropna() removes any row that has at least one missing value. It is clean and simple, but it can quietly delete a lot of data.

clean = df.dropna()

Dropping Columns Instead

If one column is mostly empty, drop the whole column with axis=1. Sometimes a single bad column hurts more than the rows it sits in.

df.dropna(axis=1)

When Dropping Is Safe

Dropping works well when gaps are rare and scattered. Losing a tiny fraction of a large dataset rarely changes your conclusions.

When Dropping Hurts

If many rows share even one gap, dropping can shrink your data drastically. Worse, the rows you lose may not be random, which biases results.

Filling the Gaps

The alternative is to fill missing cells with a sensible value using fillna(). You keep every row, at the cost of inventing some numbers.

df.fillna(0)

Filling Is a Guess

Remember that every filled value is an estimate. A good fill is reasonable and documented; a careless one hides the gap and warps your stats.

The thresh Middle Ground

You can keep rows that have enough real data using thresh, which sets the minimum number of non-missing values a row must have to survive.

df.dropna(thresh=3)

Target One Column

Use subset to drop rows only when a specific key column is missing. This protects the rest of your data from unnecessary deletion.

df.dropna(subset=['price'])

Ask Why It Is Missing

Before deciding, ask why the value is absent. Data missing at random is safe to fill, but a systematic gap may itself be a meaningful signal.

A Simple Rule of Thumb

A handy guide: drop when gaps are few, fill when rows are precious. Always weigh how each choice reshapes your distribution before committing.

Quick Check

A column is 80% empty but every row has useful data elsewhere. What is usually the wisest move?

Recap: Choose With Intent

You now weigh drop versus fill by how much data you lose and why values are missing. Use dropna, thresh, and subset to delete with care.

Frequently asked questions

Is the “Drop vs Fill: Choosing Wisely” lesson free?

Yes — the full text of “Drop vs Fill: Choosing Wisely” is free to read here on the web, and the Data Science Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Data Science Academy course, upgrade to CoddyKit PRO.

What will I learn in “Drop vs Fill: Choosing Wisely”?

When to remove and when to impute. You practise Data Science Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Data Science Academy?

No prior experience is required. Data Science Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Drop vs Fill: Choosing Wisely” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Data Science Academy lesson?

Yes. Every Data Science Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Find the NaNs Hiding in Your Table
  2. Drop vs Fill: Choosing Wisely
  3. Impute With Mean, Median, or Mode
  4. Fix dtypes and Duplicate Rows
← Back to Data Science Academy