0Pricing
Data Science Academy · درس

تحويل الأرقام إلى فئات

استخدام cut وqcut للنطاقات

تحويل الأرقام إلى فئات درس مجاني في Data Science Academy على CoddyKit. هذا هو الدرس 1 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في Data Science Academy، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة Data Science Academy 4 دروس في المجموع.

بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.

Why Bin a Number

Sometimes a raw number like age tells you less than a label like young or senior. Binning turns a continuous value into tidy groups. 🪣

Bins Reveal Patterns

Models and charts often read categories more clearly than exact figures. Grouping prices into low, mid, and high can surface trends you would otherwise miss.

Meet pandas cut

The cut function slices a column into bins you define by edges. You give it the boundaries, and it labels each value for you.

import pandas as pd
ages = pd.Series([7, 22, 45, 70])
bins = pd.cut(ages, [0, 18, 60, 100])

Name Your Bins

Pass labels so each bin has a friendly name instead of an interval. Now your output reads like a real category, not a math range.

pd.cut(ages, [0, 18, 60, 100],
       labels=['child', 'adult', 'senior'])

Edges Are Inclusive Right

By default cut includes the right edge of each bin and excludes the left. So a value of 18 lands in the first bin, not the second.

Flip With right=False

Want the left edge included instead? Set right=False and the boundary behavior flips, so 18 moves into the next bin up.

pd.cut(ages, [0, 18, 60, 100], right=False)

Equal-Width Bins

Give cut a single number instead of edges and it creates that many equal-width bins automatically across the value range.

pd.cut(ages, 4)

Meet pandas qcut

The qcut function splits by quantiles, so each bin holds roughly the same number of rows. Great when your data is lopsided.

pd.qcut(ages, 4)

cut vs qcut

Use cut for fixed, meaningful edges like price tiers. Use qcut when you want balanced groups such as quartiles of income.

Bins Become a Feature

The result is a categorical column you can drop straight into your DataFrame and feed to grouping, plotting, or a model.

df['age_group'] = pd.cut(df['age'],
                         [0, 18, 60, 100])

Watch the Out-of-Range

Values outside your bin edges become NaN. Always set edges that cover your real minimum and maximum, or you will silently lose rows.

Quick Check

You want four groups that each hold about the same number of rows. Which tool fits?

Recap: Binning

You learned to group numbers into labels: cut for chosen edges and equal widths, qcut for equal counts. Mind the edges and you turn raw values into useful features. 🎉

الأسئلة الشائعة

هل درس «تحويل الأرقام إلى فئات» مجاني؟

نعم — نص درس «تحويل الأرقام إلى فئات» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة Data Science Academy، انتقل إلى CoddyKit PRO. تتضمن دورة Data Science Academy 4 دروس في المجموع.

ماذا ستتعلم في «تحويل الأرقام إلى فئات»؟

استخدام cut وqcut للنطاقات تتمرن على Data Science Academy مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.

هل أحتاج إلى خبرة سابقة لأبدأ Data Science Academy؟

لا تُشترط خبرة سابقة. Data Science Academy على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 1 من أصل 4.

كم من الوقت يستغرق درس «تحويل الأرقام إلى فئات»؟

معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.

هل يمكنني كتابة وتشغيل أكواد في درس Data Science Academy هذا؟

نعم. كل درس في Data Science Academy يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.

جميع الدروس في هذه الدورة

  1. تحويل الأرقام إلى فئات
  2. ترميز الأعمدة الفئوية
  3. تحجيم الأرقام وتطبيعها
  4. إنشاء ميزات من التواريخ والنصوص
← العودة إلى Data Science Academy