From d900d5f46185b38bbb008e95b813877aeb66cb0d Mon Sep 17 00:00:00 2001 From: Mark Graham Date: Tue, 17 Nov 2020 17:02:54 +0000 Subject: [PATCH 1/2] add two new examples to the docs --- pandas/core/shared_docs.py | 53 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/pandas/core/shared_docs.py b/pandas/core/shared_docs.py index cc918c27b5c2e..8d1f4ac4f9578 100644 --- a/pandas/core/shared_docs.py +++ b/pandas/core/shared_docs.py @@ -324,4 +324,57 @@ 0 0.000000 1.000000 1 1.000000 2.718282 2 1.414214 7.389056 + +It is possible to call transform on a GroupBy object: + +>>> df = pd.DataFrame({{ +... "Date": [ +... "2015-05-08", "2015-05-07", "2015-05-06", "2015-05-05", +... "2015-05-08", "2015-05-07", "2015-05-06", "2015-05-05"], +... "Data": [5, 8, 6, 1, 50, 100, 60, 120], +... }}) +>>> df + Date Data +0 2015-05-08 5 +1 2015-05-07 8 +2 2015-05-06 6 +3 2015-05-05 1 +4 2015-05-08 50 +5 2015-05-07 100 +6 2015-05-06 60 +7 2015-05-05 120 +>>> df.groupby('Date')['Data'].transform('sum') +0 55 +1 108 +2 66 +3 121 +4 55 +5 108 +6 66 +7 121 +Name: Data, dtype: int64 + +>>> df = pd.DataFrame({{ +... "c": [1, 1, 1, 2, 2, 2, 2], +... "type": ["m", "n", "o", "m", "m", "n", "n"] +... }}) +>>> df + c type +0 1 m +1 1 n +2 1 o +3 2 m +4 2 m +5 2 n +6 2 n +>>> df['size'] = df.groupby('c')['type'].transform(len) +>>> df + c type size +0 1 m 3 +1 1 n 3 +2 1 o 3 +3 2 m 4 +4 2 m 4 +5 2 n 4 +6 2 n 4 """ From 5c96a68e149537f76133df918fa8ad0ee0a5091f Mon Sep 17 00:00:00 2001 From: Mark Graham Date: Thu, 19 Nov 2020 10:16:09 +0000 Subject: [PATCH 2/2] amend wording --- pandas/core/shared_docs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/shared_docs.py b/pandas/core/shared_docs.py index 8d1f4ac4f9578..03e39624253b2 100644 --- a/pandas/core/shared_docs.py +++ b/pandas/core/shared_docs.py @@ -325,7 +325,7 @@ 1 1.000000 2.718282 2 1.414214 7.389056 -It is possible to call transform on a GroupBy object: +You can call transform on a GroupBy object: >>> df = pd.DataFrame({{ ... "Date": [