From 86d51ce3607d644e143058ac420eb442246f0be6 Mon Sep 17 00:00:00 2001 From: Uday Anand <145287833+udayanand22@users.noreply.github.com> Date: Tue, 8 Apr 2025 15:46:28 +0000 Subject: [PATCH 1/2] DOC: Add real-world aggregation example to GroupBy user guide --- doc/source/user_guide/groupby.rst | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/doc/source/user_guide/groupby.rst b/doc/source/user_guide/groupby.rst index 4ec34db6ed959..e58c36a4d1a19 100644 --- a/doc/source/user_guide/groupby.rst +++ b/doc/source/user_guide/groupby.rst @@ -488,6 +488,19 @@ column in a group of values. animals animals.groupby("kind").sum() +Another real-world style example using sales data: + +.. ipython:: python + + df = pd.DataFrame({ + "Region": ["East", "West", "East", "West"], + "Sales": [250, 300, 150, 200] + }) + df + df.groupby("Region")["Sales"].sum() + + + In the result, the keys of the groups appear in the index by default. They can be instead included in the columns by passing ``as_index=False``. From d3c81d78799ece5dc32b5ed5d90e2a1231d3fa1a Mon Sep 17 00:00:00 2001 From: Uday Anand <145287833+udayanand22@users.noreply.github.com> Date: Tue, 8 Apr 2025 15:55:36 +0000 Subject: [PATCH 2/2] DOC: Fix existing RST formatting issue in groupby.rst --- doc/source/user_guide/groupby.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/doc/source/user_guide/groupby.rst b/doc/source/user_guide/groupby.rst index e58c36a4d1a19..ad2edd5c4e0ee 100644 --- a/doc/source/user_guide/groupby.rst +++ b/doc/source/user_guide/groupby.rst @@ -1590,7 +1590,8 @@ order they are first observed. Plotting ~~~~~~~~ -Groupby also works with some plotting methods. In this case, suppose we +GroupBy also works with some plotting methods. In this case, suppose we + suspect that the values in column 1 are 3 times higher on average in group "B".