Data Science · मराठी आवृत्ती
रवींद्र बागले यांच्या course वर आधारित · सहज मराठीत explanation
City आणि festival अशी दोन keys वापरून प्रत्येक जोडीची summary बनवू. Output columns ना सुरुवातीपासून स्पष्ट नावं देऊ:
summary = (
df.groupby(["city", "festival"], as_index=False)
.agg(
gmv=("amount", "sum"),
orders=("order_id", "nunique"),
avg_ticket=("amount", "mean"),
)
)
summary.sort_values("gmv", ascending=False)
Jupyter मध्ये steps मागच्या lesson मधला df तयार करा. groupby("city")["amount"].sum() run करा.वरची named aggregation वापरून summary बनवा. summary[summary["festival"] == "Diwali"] वापरून filter करा.काल्पनिक sample मध्ये Pune चा Diwali GMV हा त्याच्या None group पेक्षा जास्त आहे. Nashik ची Diwali row दिसेल; त्याच city ची None row या sample मध्ये नसल्यामुळे Nashik साठी तुलना करता येत नाही.
रवींद्र बागले यांची tip
English मराठी हिंदी
After groupby(...)["amount"].sum() you get a Series, and the group names sit in the index instead of in normal columns. For a report table, use as_index=False with named aggregation like gmv=("amount", "sum"). Every result column then gets a clear name, and you can sort, filter or export it easily.
groupby(...)["amount"].sum() नंतर Series मिळते, आणि group ची नावं normal columns ऐवजी index मध्ये जातात. Report table साठी as_index=False सोबत gmv=("amount", "sum") सारखं named aggregation वापरा. मग प्रत्येक result column ला स्पष्ट नाव मिळतं, आणि ते sort, filter किंवा export करणं सोपं जातं.
groupby(...)["amount"].sum() के बाद Series मिलती है, और group के नाम normal columns की जगह index में चले जाते हैं। Report table के लिए as_index=False के साथ gmv=("amount", "sum") जैसा named aggregation लगाओ। फिर हर result column को साफ़ नाम मिलता है, और उसे sort, filter या export करना आसान हो जाता है।
मागील: 7.1 GroupBy कशासाठी? पुढील: 7.3 value_counts की GroupBy?