@@ -1668,6 +1668,67 @@ def sem(self, ddof: int = 1):
1668
1668
result .iloc [:, result_ilocs ] /= np .sqrt (counts .iloc [:, count_ilocs ])
1669
1669
return result
1670
1670
1671
+ @final
1672
+ @Substitution (name = "groupby" )
1673
+ def kurtosis (self , how : str = 'Fisher' , numeric_only : bool = True ):
1674
+ """
1675
+ Compute kurtosis of groups, excluding missing values.
1676
+ Kurtosis is defined as the fourth central moment divided
1677
+ by the square of the variance.
1678
+
1679
+ Parameters
1680
+ ----------
1681
+ method: str
1682
+ 'Fisher' or 'Pearson' kurtosis
1683
+ numeric_only: bool
1684
+ Only numeric values
1685
+
1686
+ Returns
1687
+ -------
1688
+ Series or DataFrame
1689
+ kurtosis values within each group.
1690
+
1691
+ """
1692
+ def kurtosis_ (obj : FrameOrSeries , axis : int = 1 ):
1693
+ def kurtosis (x : Series ) -> float :
1694
+ """
1695
+ Compute the kurtosis of the pandas.Series, excluding missing values.
1696
+
1697
+ Parameters
1698
+ ----------
1699
+ pandas.Series :
1700
+ Series from which the kurtosis is calculated
1701
+
1702
+ Returns
1703
+ -------
1704
+ float
1705
+ kurtosis
1706
+ """
1707
+
1708
+ x = x .dropna (inplace = False )
1709
+ if not len (x ):
1710
+ return None
1711
+
1712
+ if how == 'Fisher' :
1713
+ return x .kurtosis ()
1714
+ elif how == 'Pearson' :
1715
+ return x .kurtosis () - 3
1716
+ else :
1717
+ raise ValueError (f'{ how } is not a valid argument' )
1718
+
1719
+ if isinstance (obj , DataFrame ):
1720
+ return obj .apply (kurtosis , axis = axis )
1721
+ elif isinstance (obj , Series ):
1722
+ return kurtosis (obj )
1723
+ else :
1724
+ raise TypeError (type (obj ))
1725
+
1726
+ return self ._agg_general (
1727
+ numeric_only = numeric_only ,
1728
+ alias = "kurtosis" ,
1729
+ npfunc = kurtosis_ ,
1730
+ )
1731
+
1671
1732
@final
1672
1733
@Substitution (name = "groupby" )
1673
1734
@Appender (_common_see_also )
0 commit comments