0Pricing
Data Science Academy · درس

تجميعات متعددة باستخدام agg

دوال مختلفة لكل عمود

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

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

Why One Number Is Not Enough

A single mean hides a lot. With agg you can request several summaries at once and see the fuller picture.

Meet agg

The agg method takes a list of functions and runs every one of them on each group in a single pass.

df.groupby("city")["sales"].agg(["mean", "max"])

A List of Function Names

Pass plain strings like "sum" or "min", and pandas maps each to its built-in aggregation for you.

g.agg(["sum", "min", "max"])

Each Function Becomes a Column

With a list of functions, the result gains one column per function, neatly side by side for comparison.

Different Functions Per Column

Pass a dictionary to apply different aggregations to different columns in the very same call.

df.groupby("city").agg({"sales": "sum", "age": "mean"})

Name Your Output Columns

Named aggregation lets you label results clearly, so you never guess what each output column means.

g.agg(total=("sales", "sum"))

Use Your Own Function

Any function returning one value works, so a custom lambda can compute a range or anything you like.

g.agg(lambda s: s.max() - s.min())

Mixing Built-ins and Custom

Inside one list you can blend string names with your own callables; pandas applies each to every group.

g.agg(["mean", lambda s: s.std()])

Aggregating Many Columns at Once

Skip selecting a column and agg runs across every numeric column, giving a wide summary table.

df.groupby("city").agg("mean")

Reset the Index to Flatten

Call reset_index afterward to turn the group keys back into normal columns for easy charting or merging.

result.reset_index()

Read the Result Carefully

When functions and columns multiply, you get a MultiIndex on columns; read it as (column, function) pairs.

Quick Check

You want sum on one column and mean on another. What do you pass to agg?

Recap: agg Is Your Swiss Knife

You can now stack many summaries, mix built-ins with custom functions, and name outputs, all through one flexible agg call. 🛠️

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

هل درس «تجميعات متعددة باستخدام agg» مجاني؟

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

ماذا ستتعلم في «تجميعات متعددة باستخدام agg»؟

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

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

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

كم من الوقت يستغرق درس «تجميعات متعددة باستخدام agg»؟

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

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

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

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

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