الحذف أم الملء: الاختيار بحكمة
متى تحذف ومتى تعوّض القيم
الحذف أم الملء: الاختيار بحكمة درس مجاني في Data Science Academy على CoddyKit. هذا هو الدرس 2 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 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.
الأسئلة الشائعة
هل درس «الحذف أم الملء: الاختيار بحكمة» مجاني؟
نعم — نص درس «الحذف أم الملء: الاختيار بحكمة» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة Data Science Academy، انتقل إلى CoddyKit PRO. تتضمن دورة Data Science Academy 4 دروس في المجموع.
ماذا ستتعلم في «الحذف أم الملء: الاختيار بحكمة»؟
متى تحذف ومتى تعوّض القيم تتمرن على Data Science Academy مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.
هل أحتاج إلى خبرة سابقة لأبدأ Data Science Academy؟
لا تُشترط خبرة سابقة. Data Science Academy على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 2 من أصل 4.
كم من الوقت يستغرق درس «الحذف أم الملء: الاختيار بحكمة»؟
معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.
هل يمكنني كتابة وتشغيل أكواد في درس Data Science Academy هذا؟
نعم. كل درس في Data Science Academy يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.
جميع الدروس في هذه الدورة
- العثور على NaNs المختبئة في جدولك
- الحذف أم الملء: الاختيار بحكمة
- التعويض بالمتوسط أو الوسيط أو المنوال
- إصلاح dtypes والصفوف المكررة