當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。