0Pricing
Data Science Academy · درس

شرح Split-Apply-Combine

النموذج الذي يقوم عليه كل groupby

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

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

One Idea, Three Steps

Every groupby follows one rhythm: split the rows into groups, apply a calculation to each, then combine the answers back together. 🔁

Split: Cut by a Key

The split step partitions rows by a key column, so all rows sharing the same value land in the same little group.

groups = df.groupby("city")

Apply: Do Work Per Group

In the apply step, the same function runs on each group on its own, never mixing one group with another.

df.groupby("city")["sales"].mean()

Combine: Stitch Results

The combine step glues each group result into one tidy output, indexed by the group keys you split on.

groupby Is Lazy

Calling groupby alone does almost nothing; it just remembers the plan. The real work waits until you add an aggregation.

g = df.groupby("city")  # no math yet

The Group Key Becomes the Index

After aggregating, your group key moves into the result index, so each unique value labels one output row.

Pick a Column to Aggregate

Select a column after grouping to focus the math. Here you ask for the average sales within each city.

df.groupby("city")["sales"].mean()

size Counts Rows Per Group

Use size when you just want how many rows fell into each group, including any missing values.

df.groupby("city").size()

Iterating Over Groups

You can loop a groupby to inspect it: each turn hands you the group name and the matching sub-table.

for name, part in df.groupby("city"):
    print(name, len(part))

Why It Beats Manual Loops

Split-apply-combine replaces slow hand-written loops with one fast, readable line that pandas optimizes for you. ⚡

A Tiny End-to-End Example

This single line splits by region, averages each group, and combines the result, all in one readable expression.

df.groupby("region")["revenue"].mean()

Quick Check

Which step actually does the calculation?

Recap: The groupby Rhythm

You learned the heartbeat of grouping: split, apply, combine. Master this rhythm and every aggregation later feels natural. 🎯

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

هل درس «شرح Split-Apply-Combine» مجاني؟

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

ماذا ستتعلم في «شرح Split-Apply-Combine»؟

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

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

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

كم من الوقت يستغرق درس «شرح Split-Apply-Combine»؟

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

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

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

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

  1. شرح Split-Apply-Combine
  2. تجميعات متعددة باستخدام agg
  3. التجميع حسب عدة مفاتيح
  4. استخدام transform لإنشاء ميزات حسب المجموعة
← العودة إلى Data Science Academy