From 177597aa3b878b3b6407615c688756bc3a9c6925 Mon Sep 17 00:00:00 2001 From: abo7atm Date: Sat, 14 Nov 2020 22:22:20 +0300 Subject: [PATCH 1/6] DOC: add unqiue value counts example to groupyby guide Co-authored-by: Abdulelah Almesfer <28743265+abdulelahsm@users.noreply.github.com> Co-authoerd-by: Abdulellah Alnumay <33042538+Abo7atm@users.noreply.github.com> --- doc/source/user_guide/groupby.rst | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/doc/source/user_guide/groupby.rst b/doc/source/user_guide/groupby.rst index 87ead5a1b80f0..dff0903871093 100644 --- a/doc/source/user_guide/groupby.rst +++ b/doc/source/user_guide/groupby.rst @@ -524,6 +524,13 @@ index are the group names and whose values are the sizes of each group. grouped.describe() +Another aggregation example is to compute the number of unique values of a group. This is similar to the ``value_counts`` function, execpt that ``value_counts`` return the number of all values instead of the number of unique values. + +.. ipython:: python + + l = [['foo', 1], ['foo', 2], ['foo', 2], ['bar', 1], ['bar', 1]] + pd.DataFrame(l, columns=['A', 'B']).groupby('A').nunique() + .. note:: Aggregation functions **will not** return the groups that you are aggregating over From 01e2036311ede4d4c52d9b93b716b8860a32d3f0 Mon Sep 17 00:00:00 2001 From: abo7atm Date: Sat, 14 Nov 2020 22:44:34 +0300 Subject: [PATCH 2/6] fix test error and run precommit Co-authored-by: Abdulelah Almesfer <28743265+abdulelahsm@users.noreply.github.com> Co-authoerd-by: Abdulellah Alnumay <33042538+Abo7atm@users.noreply.github.com> --- doc/source/user_guide/groupby.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/user_guide/groupby.rst b/doc/source/user_guide/groupby.rst index dff0903871093..9a8a5504c6a94 100644 --- a/doc/source/user_guide/groupby.rst +++ b/doc/source/user_guide/groupby.rst @@ -528,7 +528,7 @@ Another aggregation example is to compute the number of unique values of a group .. ipython:: python - l = [['foo', 1], ['foo', 2], ['foo', 2], ['bar', 1], ['bar', 1]] + ll = [['foo', 1], ['foo', 2], ['foo', 2], ['bar', 1], ['bar', 1]] pd.DataFrame(l, columns=['A', 'B']).groupby('A').nunique() .. note:: From 80c686cb0e6c83c19dc68f213e08a5573cdc6137 Mon Sep 17 00:00:00 2001 From: abo7atm Date: Sun, 15 Nov 2020 01:48:59 +0300 Subject: [PATCH 3/6] fix variable name in second line of example Co-authored-by: Abdulelah Almesfer <28743265+abdulelahsm@users.noreply.github.com> Co-authoerd-by: Abdulellah Alnumay <33042538+Abo7atm@users.noreply.github.com> --- doc/source/user_guide/groupby.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/user_guide/groupby.rst b/doc/source/user_guide/groupby.rst index 9a8a5504c6a94..939d1a1eae0ca 100644 --- a/doc/source/user_guide/groupby.rst +++ b/doc/source/user_guide/groupby.rst @@ -529,7 +529,7 @@ Another aggregation example is to compute the number of unique values of a group .. ipython:: python ll = [['foo', 1], ['foo', 2], ['foo', 2], ['bar', 1], ['bar', 1]] - pd.DataFrame(l, columns=['A', 'B']).groupby('A').nunique() + pd.DataFrame(ll, columns=['A', 'B']).groupby('A').nunique() .. note:: From ed274f84bd8e3fd7199763b0d19fb26d015bd51e Mon Sep 17 00:00:00 2001 From: Abo7atm <33042538+Abo7atm@users.noreply.github.com> Date: Sun, 15 Nov 2020 18:39:31 +0300 Subject: [PATCH 4/6] Update doc/source/user_guide/groupby.rst Co-authored-by: Marco Gorelli --- doc/source/user_guide/groupby.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/user_guide/groupby.rst b/doc/source/user_guide/groupby.rst index 939d1a1eae0ca..61c534d47809c 100644 --- a/doc/source/user_guide/groupby.rst +++ b/doc/source/user_guide/groupby.rst @@ -524,7 +524,7 @@ index are the group names and whose values are the sizes of each group. grouped.describe() -Another aggregation example is to compute the number of unique values of a group. This is similar to the ``value_counts`` function, execpt that ``value_counts`` return the number of all values instead of the number of unique values. +Another aggregation example is to compute the number of unique values of each group. This is similar to the ``value_counts`` function, except that it only counts unique values. .. ipython:: python From 89e458556c1bd5c675999676f321be18aa2e864f Mon Sep 17 00:00:00 2001 From: Abo7atm <33042538+Abo7atm@users.noreply.github.com> Date: Sun, 15 Nov 2020 18:39:37 +0300 Subject: [PATCH 5/6] Update doc/source/user_guide/groupby.rst Co-authored-by: Marco Gorelli --- doc/source/user_guide/groupby.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/user_guide/groupby.rst b/doc/source/user_guide/groupby.rst index 61c534d47809c..66ed5a72f6438 100644 --- a/doc/source/user_guide/groupby.rst +++ b/doc/source/user_guide/groupby.rst @@ -529,7 +529,7 @@ Another aggregation example is to compute the number of unique values of each gr .. ipython:: python ll = [['foo', 1], ['foo', 2], ['foo', 2], ['bar', 1], ['bar', 1]] - pd.DataFrame(ll, columns=['A', 'B']).groupby('A').nunique() + pd.DataFrame(ll, columns=["A", "B"]).groupby("A")["B"].nunique() .. note:: From d0474302ff597c623549bb557b9d976e99cff445 Mon Sep 17 00:00:00 2001 From: abo7atm Date: Wed, 18 Nov 2020 17:38:18 +0300 Subject: [PATCH 6/6] show dataframe before applying groupby --- doc/source/user_guide/groupby.rst | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/doc/source/user_guide/groupby.rst b/doc/source/user_guide/groupby.rst index 66ed5a72f6438..21df3cab68a09 100644 --- a/doc/source/user_guide/groupby.rst +++ b/doc/source/user_guide/groupby.rst @@ -529,7 +529,9 @@ Another aggregation example is to compute the number of unique values of each gr .. ipython:: python ll = [['foo', 1], ['foo', 2], ['foo', 2], ['bar', 1], ['bar', 1]] - pd.DataFrame(ll, columns=["A", "B"]).groupby("A")["B"].nunique() + df4 = pd.DataFrame(ll, columns=["A", "B"]) + df4 + df4.groupby("A")["B"].nunique() .. note::