إصلاح dtypes والصفوف المكررة
تحويل الأنواع وحذف التكرارات
إصلاح dtypes والصفوف المكررة درس مجاني في Data Science Academy على CoddyKit. هذا هو الدرس 4 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في Data Science Academy، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة Data Science Academy 4 دروس في المجموع.
بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.
Clean Goes Beyond Gaps
Filling missing values is only half the job. Clean data also needs correct dtypes and no accidental duplicate rows muddying your counts. 🧹
What a dtype Is
Every column has a dtype, its data type, like int, float, object, or datetime. The dtype controls which operations the column even allows.
df.dtypesNumbers Stuck as Text
A frequent mess: numbers loaded as object strings because one stray symbol crept in. You cannot do math on them until the type is fixed.
Coerce With to_numeric
Convert a text column to numbers with to_numeric. Pass errors='coerce' to turn anything unparseable into NaN instead of crashing.
df['price'] = pd.to_numeric(df['price'], errors='coerce')Cast With astype
When a column is already clean, astype changes its type directly, for example turning whole-number floats back into compact integers.
df['count'] = df['count'].astype(int)Fix Date Columns
Dates often arrive as text. Convert them with to_datetime so you can sort, filter by range, and extract parts like month later.
df['date'] = pd.to_datetime(df['date'])Category to Save Memory
Columns with few repeated text values shrink dramatically as the category dtype, which stores each label once and references it.
df['city'] = df['city'].astype('category')Spotting Duplicate Rows
Repeated records inflate totals and averages. Find them with duplicated(), which flags each row that has appeared before as True.
df.duplicated().sum()Dropping Duplicates
Remove repeats with drop_duplicates(). By default it keeps the first occurrence of each row and discards the rest.
df = df.drop_duplicates()Duplicates by Key Columns
Sometimes only certain columns define a duplicate. Pass subset to detect repeats based on a key like an id, ignoring the other columns.
df.drop_duplicates(subset=['user_id'])Verify Before You Move On
After fixing types and repeats, run info() once more. Confirming dtypes and row counts protects you from cleaning errors slipping downstream.
df.info()Quick Check
A price column loaded as object text. Which call safely turns bad entries into NaN?
Recap: Types and Dupes Tamed
You now fix dtypes with to_numeric, astype, and to_datetime, and clear repeats with drop_duplicates. Your table is finally analysis-ready.
الأسئلة الشائعة
هل درس «إصلاح dtypes والصفوف المكررة» مجاني؟
نعم — نص درس «إصلاح dtypes والصفوف المكررة» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة Data Science Academy، انتقل إلى CoddyKit PRO. تتضمن دورة Data Science Academy 4 دروس في المجموع.
ماذا ستتعلم في «إصلاح dtypes والصفوف المكررة»؟
تحويل الأنواع وحذف التكرارات تتمرن على Data Science Academy مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.
هل أحتاج إلى خبرة سابقة لأبدأ Data Science Academy؟
لا تُشترط خبرة سابقة. Data Science Academy على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 4 من أصل 4.
كم من الوقت يستغرق درس «إصلاح dtypes والصفوف المكررة»؟
معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.
هل يمكنني كتابة وتشغيل أكواد في درس Data Science Academy هذا؟
نعم. كل درس في Data Science Academy يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.
جميع الدروس في هذه الدورة
- العثور على NaNs المختبئة في جدولك
- الحذف أم الملء: الاختيار بحكمة
- التعويض بالمتوسط أو الوسيط أو المنوال
- إصلاح dtypes والصفوف المكررة