← Back to Pandas Course | Chapter 7: Grouping & Aggregation | Lesson 2 of 7

agg() के Functions

agg एक ही call में आपके groups पर एक या कई summary functions apply करता है।

In this page:

  1. agg() functions
Syntax
python
df.groupby("column").agg("function_name")
df.groupby("column").agg({"column1": "sum", "column2": "mean"})

agg() functions

agg एक function name, names की list, या columns को functions से map करने वाला dict accept करता है। sum, mean, min, max, count और std आम choices हैं। यह Series, DataFrames और groupby objects पर काम करता है।

Note: {"salary": "mean", "age": "max"} जैसा dict हर column पर अलग function apply करता है।

उदाहरण: agg() functions

python
import pandas as pd

df = pd.DataFrame({"dept": ["A", "B", "A", "B"], "salary": [100, 200, 150, 250], "age": [30, 40, 35, 45]})
print(df.groupby("dept").agg({"salary": "mean", "age": "max"}))
print(df["salary"].agg(["min", "max"]))

# Output:
#       salary  age
# dept
# A      125.0   35
# B      225.0   45
# min    100
# max    250
# Name: salary, dtype: int64
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
आम गलतियां
  1. गलत function name string का उपयोग करना
  2. यह भूल जाना कि agg एक नया object return करता है
  3. text columns पर numeric functions apply करना
चैप्टर सारांश
  • agg names, lists या dicts लेता है
  • groupby के साथ काम करता है
  • Dicts हर column पर function बदलते हैं
  • आम: sum, mean, min, max
🔒

Chapter Quiz — Complete all 7 topics to unlock

0/7 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.