0Pricing
Data Science Academy · บทเรียน

ลบหรือเติม: เลือกให้เหมาะสม

เมื่อใดควรลบ และเมื่อใดควรแทนค่า

ลบหรือเติม: เลือกให้เหมาะสม เป็นบทเรียน Data Science Academy ฟรีบน CoddyKit นี่คือบทเรียนที่ 2 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน Data Science Academy และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส Data Science Academy มีบทเรียนทั้งหมด 4 บทเรียน

บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ

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.

คำถามที่พบบ่อย

บทเรียน “ลบหรือเติม: เลือกให้เหมาะสม” ฟรีหรือไม่

ใช่ — ข้อความเต็มของ “ลบหรือเติม: เลือกให้เหมาะสม” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส Data Science Academy ให้อัปเกรดเป็น CoddyKit PRO คอร์ส Data Science Academy มีบทเรียนทั้งหมด 4 บทเรียน

คุณจะเรียนรู้อะไรในบทเรียน “ลบหรือเติม: เลือกให้เหมาะสม”

เมื่อใดควรลบ และเมื่อใดควรแทนค่า คุณปฏิบัติ Data Science Academy ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน

คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน Data Science Academy หรือไม่

ไม่จำเป็นต้องมีประสบการณ์มาก่อน Data Science Academy บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 2 จากทั้งหมด 4 บทเรียน

บทเรียน “ลบหรือเติม: เลือกให้เหมาะสม” ใช้เวลานานแค่ไหน

บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย

ฉันเขียนและรันโค้ดในบทเรียน Data Science Academy นี้ได้ไหม

ได้ บทเรียน Data Science Academy ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ

บทเรียนทั้งหมดในหลักสูตรนี้

  1. ค้นหา NaNs ที่ซ่อนอยู่ในตาราง
  2. ลบหรือเติม: เลือกให้เหมาะสม
  3. แทนค่าด้วยค่าเฉลี่ย มัธยฐาน หรือฐานนิยม
  4. แก้ไข dtypes และแถวซ้ำ
← กลับไปที่ Data Science Academy