agg() के Functions
agg एक ही call में आपके groups पर एक या कई summary functions apply करता है।
In this page:
Syntax
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
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. #}
आम गलतियां
- गलत function name string का उपयोग करना
- यह भूल जाना कि agg एक नया object return करता है
- 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: