当前位置: 首页>>代码示例>>Python>>正文


Python Series.value_counts方法代码示例

本文整理汇总了Python中pandas.core.series.Series.value_counts方法的典型用法代码示例。如果您正苦于以下问题:Python Series.value_counts方法的具体用法?Python Series.value_counts怎么用?Python Series.value_counts使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pandas.core.series.Series的用法示例。


在下文中一共展示了Series.value_counts方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: describe

# 需要导入模块: from pandas.core.series import Series [as 别名]
# 或者: from pandas.core.series.Series import value_counts [as 别名]
def describe(self):
        """
        Describes this Categorical

        Returns
        -------
        description: `DataFrame`
            A dataframe with frequency and counts by category.
        """
        counts = self.value_counts(dropna=False)
        freqs = counts / float(counts.sum())

        from pandas.core.reshape.concat import concat
        result = concat([counts, freqs], axis=1)
        result.columns = ['counts', 'freqs']
        result.index.name = 'categories'

        return result 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:20,代码来源:categorical.py

示例2: describe

# 需要导入模块: from pandas.core.series import Series [as 别名]
# 或者: from pandas.core.series.Series import value_counts [as 别名]
def describe(self):
        """ Describes this Categorical

        Returns
        -------
        description: `DataFrame`
            A dataframe with frequency and counts by category.
        """
        counts = self.value_counts(dropna=False)
        freqs = counts / float(counts.sum())

        from pandas.core.reshape.concat import concat
        result = concat([counts, freqs], axis=1)
        result.columns = ['counts', 'freqs']
        result.index.name = 'categories'

        return result 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:19,代码来源:categorical.py

示例3: value_counts

# 需要导入模块: from pandas.core.series import Series [as 别名]
# 或者: from pandas.core.series.Series import value_counts [as 别名]
def value_counts(self, dropna=True):
        """
        Returns a Series containing counts of each category.

        Every category will have an entry, even those with a count of 0.

        Parameters
        ----------
        dropna : boolean, default True
            Don't include counts of NaN.

        Returns
        -------
        counts : Series

        See Also
        --------
        Series.value_counts

        """
        from numpy import bincount
        from pandas import Series, CategoricalIndex

        code, cat = self._codes, self.categories
        ncat, mask = len(cat), 0 <= code
        ix, clean = np.arange(ncat), mask.all()

        if dropna or clean:
            obs = code if clean else code[mask]
            count = bincount(obs, minlength=ncat or None)
        else:
            count = bincount(np.where(mask, code, ncat))
            ix = np.append(ix, -1)

        ix = self._constructor(ix, dtype=self.dtype,
                               fastpath=True)

        return Series(count, index=CategoricalIndex(ix), dtype='int64') 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:40,代码来源:categorical.py

示例4: value_counts

# 需要导入模块: from pandas.core.series import Series [as 别名]
# 或者: from pandas.core.series.Series import value_counts [as 别名]
def value_counts(self, dropna=True):
        """
        Returns a Series containing counts of each category.

        Every category will have an entry, even those with a count of 0.

        Parameters
        ----------
        dropna : boolean, default True
            Don't include counts of NaN, even if NaN is a category.

        Returns
        -------
        counts : Series

        See Also
        --------
        Series.value_counts

        """
        from numpy import bincount
        from pandas import isna, Series, CategoricalIndex

        obj = (self.remove_categories([np.nan]) if dropna and
               isna(self.categories).any() else self)
        code, cat = obj._codes, obj.categories
        ncat, mask = len(cat), 0 <= code
        ix, clean = np.arange(ncat), mask.all()

        if dropna or clean:
            obs = code if clean else code[mask]
            count = bincount(obs, minlength=ncat or None)
        else:
            count = bincount(np.where(mask, code, ncat))
            ix = np.append(ix, -1)

        ix = self._constructor(ix, dtype=self.dtype,
                               fastpath=True)

        return Series(count, index=CategoricalIndex(ix), dtype='int64') 
开发者ID:nccgroup,项目名称:Splunking-Crime,代码行数:42,代码来源:categorical.py


注:本文中的pandas.core.series.Series.value_counts方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。