6868from pandas .core .groupby .groupby import (
6969 GroupBy ,
7070 GroupByPlot ,
71- _transform_template ,
7271)
7372from pandas .core .indexes .api import (
7473 Index ,
@@ -683,7 +682,8 @@ def transform(self, func, *args, engine=None, engine_kwargs=None, **kwargs):
683682 Parameters
684683 ----------
685684 func : function, str
686- Function to apply to each group. See the Notes section below for requirements.
685+ Function to apply to each group. See the Notes section below for
686+ requirements.
687687
688688 Accepted inputs are:
689689
@@ -705,7 +705,7 @@ def transform(self, func, *args, engine=None, engine_kwargs=None, **kwargs):
705705 engine : str, default None
706706 * ``'cython'`` : Runs the function through C-extensions from cython.
707707 * ``'numba'`` : Runs the function through JIT compiled code from numba.
708- * ``None`` : Defaults to ``' cython' `` or the global setting ``compute.use_numba``
708+ * ``None`` : Defaults to ``cython`` or global setting ``compute.use_numba``
709709
710710 engine_kwargs : dict, default None
711711 * For ``'cython'`` engine, there are no accepted ``engine_kwargs``
@@ -760,17 +760,19 @@ def transform(self, func, *args, engine=None, engine_kwargs=None, **kwargs):
760760
761761 .. versionchanged:: 2.0.0
762762
763- When using ``.transform`` on a grouped DataFrame and the transformation function
764- returns a DataFrame, pandas now aligns the result's index
763+ When using ``.transform`` on a grouped DataFrame and the transformation
764+ function returns a DataFrame, pandas now aligns the result's index
765765 with the input's index. You can call ``.to_numpy()`` on the
766766 result of the transformation function to avoid alignment.
767767
768768 Examples
769769 --------
770770
771- >>> ser = pd.Series([390.0, 350.0, 30.0, 20.0],
772- ... index=["Falcon", "Falcon", "Parrot", "Parrot"],
773- ... name="Max Speed")
771+ >>> ser = pd.Series(
772+ ... [390.0, 350.0, 30.0, 20.0],
773+ ... index=["Falcon", "Falcon", "Parrot", "Parrot"],
774+ ... name="Max Speed",
775+ ... )
774776 >>> grouped = ser.groupby([1, 1, 2, 2])
775777 >>> grouped.transform(lambda x: (x - x.mean()) / x.std())
776778 Falcon 0.707107
@@ -1776,8 +1778,9 @@ def plot(self) -> GroupByPlot:
17761778 .. versionadded:: 1.5.0
17771779
17781780 sharex : bool, default True if ax is None else False
1779- In case ``subplots=True``, share x axis and set some x axis labels
1780- to invisible; defaults to True if ax is None otherwise False if
1781+ In case ``subplots=True``, share x axis and set some x axis
1782+ labels to invisible;
1783+ defaults to True if ax is None otherwise False if
17811784 an ax is passed in; Be aware, that passing in both an ax and
17821785 ``sharex=True`` will alter all x axis labels for all axis in a figure.
17831786 sharey : bool, default False
@@ -1816,8 +1819,8 @@ def plot(self) -> GroupByPlot:
18161819 ylim : 2-tuple/list
18171820 Set the y limits of the current axes.
18181821 xlabel : label, optional
1819- Name to use for the xlabel on x-axis. Default uses index name as xlabel, or the
1820- x-column name for planar plots.
1822+ Name to use for the xlabel on x-axis. Default uses index name as xlabel,
1823+ or the x-column name for planar plots.
18211824
18221825 .. versionchanged:: 2.0.0
18231826
@@ -1917,7 +1920,6 @@ def plot(self) -> GroupByPlot:
19171920
19181921 .. plot::
19191922 :context: close-figs
1920-
19211923 >>> df = pd.DataFrame(
19221924 ... {
19231925 ... "length": [1.5, 0.5, 1.2, 0.9, 3],
@@ -1931,18 +1933,18 @@ def plot(self) -> GroupByPlot:
19311933
19321934 .. plot::
19331935 :context: close-figs
1934-
19351936 >>> lst = [-1, -2, -3, 1, 2, 3]
19361937 >>> ser = pd.Series([1, 2, 2, 4, 6, 6], index=lst)
19371938 >>> plot = ser.groupby(lambda x: x > 0).plot(title="SeriesGroupBy Plot")
19381939
19391940 For DataFrameGroupBy:
19401941
1941- .. plot::
1942+ .. plot::
19421943 :context: close-figs
1943-
19441944 >>> df = pd.DataFrame({"col1": [1, 2, 3, 4], "col2": ["A", "B", "A", "B"]})
1945- >>> plot = df.groupby("col2").plot(kind="bar", title="DataFrameGroupBy Plot")
1945+ >>> plot = df.groupby("col2").plot(
1946+ ... kind="bar", title="DataFrameGroupBy Plot"
1947+ ... )
19461948 """
19471949 result = GroupByPlot (self )
19481950 return result
@@ -2336,13 +2338,15 @@ def corr(
23362338
23372339 Notes
23382340 -----
2339- Pearson, Kendall and Spearman correlation are currently computed using pairwise complete observations.
2341+ Pearson, Kendall and Spearman correlation are currently computed using
2342+ pairwise complete observations.
23402343
23412344 * `Pearson correlation coefficient <https://en.wikipedia.org/wiki/Pearson_correlation_coefficient>`_
23422345 * `Kendall rank correlation coefficient <https://en.wikipedia.org/wiki/Kendall_rank_correlation_coefficient>`_
23432346 * `Spearman's rank correlation coefficient <https://en.wikipedia.org/wiki/Spearman%27s_rank_correlation_coefficient>`_
23442347
2345- Automatic data alignment: as with all pandas operations, automatic data alignment is performed for this method.
2348+ Automatic data alignment: as with all pandas operations, automatic data
2349+ alignment is performed for this method.
23462350 ``corr()`` automatically considers values with matching indices.
23472351
23482352 Examples
@@ -3241,7 +3245,7 @@ def transform(self, func, *args, engine=None, engine_kwargs=None, **kwargs):
32413245 engine : str, default None
32423246 * ``'cython'`` : Runs the function through C-extensions from cython.
32433247 * ``'numba'`` : Runs the function through JIT compiled code from numba.
3244- * ``None`` : Defaults to ``' cython' `` or the global setting ``compute.use_numba``
3248+ * ``None`` : Defaults to ``cython`` or global setting ``compute.use_numba``
32453249
32463250 engine_kwargs : dict, default None
32473251 * For ``'cython'`` engine, there are no accepted ``engine_kwargs``
@@ -3296,17 +3300,19 @@ def transform(self, func, *args, engine=None, engine_kwargs=None, **kwargs):
32963300
32973301 .. versionchanged:: 2.0.0
32983302
3299- When using ``.transform`` on a grouped DataFrame and the transformation function
3300- returns a DataFrame, pandas now aligns the result's index
3303+ When using ``.transform`` on a grouped DataFrame and the transformation
3304+ function returns a DataFrame, pandas now aligns the result's index
33013305 with the input's index. You can call ``.to_numpy()`` on the
33023306 result of the transformation function to avoid alignment.
33033307
33043308 Examples
33053309 --------
33063310
3307- >>> ser = pd.Series([390.0, 350.0, 30.0, 20.0],
3308- ... index=["Falcon", "Falcon", "Parrot", "Parrot"],
3309- ... name="Max Speed")
3311+ >>> ser = pd.Series(
3312+ ... [390.0, 350.0, 30.0, 20.0],
3313+ ... index=["Falcon", "Falcon", "Parrot", "Parrot"],
3314+ ... name="Max Speed",
3315+ ... )
33103316 >>> grouped = ser.groupby([1, 1, 2, 2])
33113317 >>> grouped.transform(lambda x: (x - x.mean()) / x.std())
33123318 Falcon 0.707107
@@ -4233,7 +4239,8 @@ def plot(self) -> GroupByPlot:
42334239 an ax is passed in; Be aware, that passing in both an ax and
42344240 ``sharex=True`` will alter all x axis labels for all axis in a figure.
42354241 sharey : bool, default False
4236- In case ``subplots=True``, share y axis and set some y axis labels to invisible.
4242+ In case ``subplots=True``, share y axis and set some y axis
4243+ labels to invisible.
42374244 layout : tuple, optional
42384245 (rows, columns) for the layout of subplots.
42394246 figsize : a tuple (width, height) in inches
@@ -4268,8 +4275,8 @@ def plot(self) -> GroupByPlot:
42684275 ylim : 2-tuple/list
42694276 Set the y limits of the current axes.
42704277 xlabel : label, optional
4271- Name to use for the xlabel on x-axis. Default uses index name as xlabel, or the
4272- x-column name for planar plots.
4278+ Name to use for the xlabel on x-axis. Default uses index name as xlabel,
4279+ or the x-column name for planar plots.
42734280
42744281 .. versionchanged:: 2.0.0
42754282
@@ -4394,7 +4401,9 @@ def plot(self) -> GroupByPlot:
43944401 :context: close-figs
43954402
43964403 >>> df = pd.DataFrame({"col1": [1, 2, 3, 4], "col2": ["A", "B", "A", "B"]})
4397- >>> plot = df.groupby("col2").plot(kind="bar", title="DataFrameGroupBy Plot")
4404+ >>> plot = df.groupby("col2").plot(
4405+ ... kind="bar", title="DataFrameGroupBy Plot"
4406+ ... )
43984407 """
43994408 result = GroupByPlot (self )
44004409 return result
@@ -4443,13 +4452,15 @@ def corr(
44434452
44444453 Notes
44454454 -----
4446- Pearson, Kendall and Spearman correlation are currently computed using pairwise complete observations.
4455+ Pearson, Kendall and Spearman correlation are currently computed using
4456+ pairwise complete observations.
44474457
44484458 * `Pearson correlation coefficient <https://en.wikipedia.org/wiki/Pearson_correlation_coefficient>`_
44494459 * `Kendall rank correlation coefficient <https://en.wikipedia.org/wiki/Kendall_rank_correlation_coefficient>`_
44504460 * `Spearman's rank correlation coefficient <https://en.wikipedia.org/wiki/Spearman%27s_rank_correlation_coefficient>`_
44514461
4452- Automatic data alignment: as with all pandas operations, automatic data alignment is performed for this method.
4462+ Automatic data alignment: as with all pandas operations,
4463+ automatic data alignment is performed for this method.
44534464 ``corr()`` automatically considers values with matching indices.
44544465
44554466 Examples
0 commit comments