Skip to content

Commit 1a48cd9

Browse files
marenwestermannMaren Westermann
and
Maren Westermann
authored
DOC: add documentation to DataFrameGroupBy.skew and SeriesGroupBy.skew (#50958)
Co-authored-by: Maren Westermann <[email protected]>
1 parent 8deae52 commit 1a48cd9

File tree

1 file changed

+115
-2
lines changed

1 file changed

+115
-2
lines changed

pandas/core/groupby/generic.py

Lines changed: 115 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,14 +1006,65 @@ def take(
10061006
result = self._op_via_apply("take", indices=indices, axis=axis, **kwargs)
10071007
return result
10081008

1009-
@doc(Series.skew.__doc__)
10101009
def skew(
10111010
self,
10121011
axis: Axis | lib.NoDefault = lib.no_default,
10131012
skipna: bool = True,
10141013
numeric_only: bool = False,
10151014
**kwargs,
10161015
) -> Series:
1016+
"""
1017+
Return unbiased skew within groups.
1018+
1019+
Normalized by N-1.
1020+
1021+
Parameters
1022+
----------
1023+
axis : {0 or 'index', 1 or 'columns', None}, default 0
1024+
Axis for the function to be applied on.
1025+
This parameter is only for compatibility with DataFrame and is unused.
1026+
1027+
skipna : bool, default True
1028+
Exclude NA/null values when computing the result.
1029+
1030+
numeric_only : bool, default False
1031+
Include only float, int, boolean columns. Not implemented for Series.
1032+
1033+
**kwargs
1034+
Additional keyword arguments to be passed to the function.
1035+
1036+
Returns
1037+
-------
1038+
Series
1039+
1040+
See Also
1041+
--------
1042+
Series.skew : Return unbiased skew over requested axis.
1043+
1044+
Examples
1045+
--------
1046+
>>> ser = pd.Series([390., 350., 357., np.nan, 22., 20., 30.],
1047+
... index=['Falcon', 'Falcon', 'Falcon', 'Falcon',
1048+
... 'Parrot', 'Parrot', 'Parrot'],
1049+
... name="Max Speed")
1050+
>>> ser
1051+
Falcon 390.0
1052+
Falcon 350.0
1053+
Falcon 357.0
1054+
Falcon NaN
1055+
Parrot 22.0
1056+
Parrot 20.0
1057+
Parrot 30.0
1058+
Name: Max Speed, dtype: float64
1059+
>>> ser.groupby(level=0).skew()
1060+
Falcon 1.525174
1061+
Parrot 1.457863
1062+
Name: Max Speed, dtype: float64
1063+
>>> ser.groupby(level=0).skew(skipna=False)
1064+
Falcon NaN
1065+
Parrot 1.457863
1066+
Name: Max Speed, dtype: float64
1067+
"""
10171068
result = self._op_via_apply(
10181069
"skew",
10191070
axis=axis,
@@ -2473,14 +2524,76 @@ def take(
24732524
result = self._op_via_apply("take", indices=indices, axis=axis, **kwargs)
24742525
return result
24752526

2476-
@doc(DataFrame.skew.__doc__)
24772527
def skew(
24782528
self,
24792529
axis: Axis | None | lib.NoDefault = lib.no_default,
24802530
skipna: bool = True,
24812531
numeric_only: bool = False,
24822532
**kwargs,
24832533
) -> DataFrame:
2534+
"""
2535+
Return unbiased skew within groups.
2536+
2537+
Normalized by N-1.
2538+
2539+
Parameters
2540+
----------
2541+
axis : {0 or 'index', 1 or 'columns', None}, default 0
2542+
Axis for the function to be applied on.
2543+
2544+
Specifying ``axis=None`` will apply the aggregation across both axes.
2545+
2546+
.. versionadded:: 2.0.0
2547+
2548+
skipna : bool, default True
2549+
Exclude NA/null values when computing the result.
2550+
2551+
numeric_only : bool, default False
2552+
Include only float, int, boolean columns.
2553+
2554+
**kwargs
2555+
Additional keyword arguments to be passed to the function.
2556+
2557+
Returns
2558+
-------
2559+
DataFrame
2560+
2561+
See Also
2562+
--------
2563+
DataFrame.skew : Return unbiased skew over requested axis.
2564+
2565+
Examples
2566+
--------
2567+
>>> arrays = [['falcon', 'parrot', 'cockatoo', 'kiwi',
2568+
... 'lion', 'monkey', 'rabbit'],
2569+
... ['bird', 'bird', 'bird', 'bird',
2570+
... 'mammal', 'mammal', 'mammal']]
2571+
>>> index = pd.MultiIndex.from_arrays(arrays, names=('name', 'class'))
2572+
>>> df = pd.DataFrame({'max_speed': [389.0, 24.0, 70.0, np.nan,
2573+
... 80.5, 21.5, 15.0]},
2574+
... index=index)
2575+
>>> df
2576+
max_speed
2577+
name class
2578+
falcon bird 389.0
2579+
parrot bird 24.0
2580+
cockatoo bird 70.0
2581+
kiwi bird NaN
2582+
lion mammal 80.5
2583+
monkey mammal 21.5
2584+
rabbit mammal 15.0
2585+
>>> gb = df.groupby(["class"])
2586+
>>> gb.skew()
2587+
max_speed
2588+
class
2589+
bird 1.628296
2590+
mammal 1.669046
2591+
>>> gb.skew(skipna=False)
2592+
max_speed
2593+
class
2594+
bird NaN
2595+
mammal 1.669046
2596+
"""
24842597
result = self._op_via_apply(
24852598
"skew",
24862599
axis=axis,

0 commit comments

Comments
 (0)