🔵 Data Science  ·  Lesson 39

GroupBy, Merge और Pivot Tables

Pandas groupby और merge क्या है?

Pandas groupby और merge ka matlab hai: groupby summarizes data by category, and merge combines two DataFrames using a common column. Simple words me, ye topic practical Python programs likhne me direct use hota hai.

Is topic ko sirf definition ke liye nahi, balki class-wise summaries jaise real examples ke liye practice karein.

यह क्यों सीखना जरूरी है?

  • Ye class-wise summaries me kaam aata hai.
  • Ye combining related tables se bhi connected hai.
  • Isse aap code ka output aur errors better samajh paate hain.

Important Terms

TermMeaning
groupbyPandas operation used to summarize data by category.
aggregationSummary calculation such as sum, average or count.
mergeCombining tables using a common column.
joinjoin is an important term in this topic.
summarysummary is an important term in this topic.

Syntax / Basic Pattern

Basic idea: pehle data तैयार करें, phir Python logic apply करें, aur finally result display करें.

Basic Pattern
import pandas as pd
df = pd.DataFrame({
    "Class": ["X", "X", "XI"],
    "Marks": [80, 90, 85]
})
summary = df.groupby("Class")["Marks"].mean()
print(summary)

Complete Example Program

Python – pandas-groupby-merge.py
import pandas as pd

df = pd.DataFrame({
    "Class": ["X", "X", "XI"],
    "Marks": [80, 90, 85]
})

summary = df.groupby("Class")["Marks"].mean()
print(summary)

Expected Output

Class X 85.0 XI 85.0 Name: Marks, dtype: float64

Program Explanation

  • import pandas as pd imports ready-made features from a module/library.
  • df = pd.DataFrame({ stores a value in df.
  • "Class": ["X", "X", "XI"], performs the next step of the program logic.
  • "Marks": [80, 90, 85] performs the next step of the program logic.
  • }) performs the next step of the program logic.
  • summary = df.groupby("Class")["Marks"].mean() stores a value in summary.
  • print(summary) displays information or calculated result on the screen.

Practical Uses

  • Class-wise summaries.
  • Combining related tables.
  • Category-wise analysis.

Common Mistakes

  • Analysing data before checking missing values, duplicates and data types.
  • Changing original data without keeping a clean copy.
  • Creating charts without title, labels or explanation.

Practice Tasks

  1. Program ko pandas-groupby-merge.py file me type karke run karein.
  2. Values change karke output compare karein.
  3. class-wise summaries par ek छोटा example banayen.
  4. Logic ko apne words me 5 lines me likhein.

सारांश

Pandas groupby and merge ko tab complete maanenge jab aap iska meaning, example, output aur practical use clearly explain kar saken.

← Back to Python Tutorial
🔗

Share this topic with a friend

यह topic किसी दोस्त को भेजें

Found it useful? Send it to a classmate learning the same thing.

अच्छा लगा? जो दोस्त यही सीख रहा है, उसे भेज दीजिए।

💻 लाइव कोड एडिटर

इस पेज के प्रोग्राम यहीं तैयार हैं — चलाएँ, बदलें और सीखें। कुछ भी इंस्टॉल किए बिना।
OneCompiler द्वारा संचालित। कोड एडिटर में अपने आप आ जाता है — Run दबाकर आउटपुट देखें। अगर एडिटर न खुले तो नए टैब में खोलें.