用法:
Series.value_counts(normalize=False, sort=True, ascending=False, bins=None, dropna=True)
返回一個包含唯一值計數的係列。
結果對象將按降序排列,因此第一個元素是最多的 frequently-occurring 元素。默認情況下排除 NA 值。
- normalize:布爾值,默認為 False
如果為 True,則返回的對象將包含唯一值的相對頻率。
- sort:布爾值,默認為真
按頻率排序。
- ascending:布爾值,默認為 False
按升序排列。
- bins:整數,可選
不是計算值,而是將它們分組到半開的箱中,使用數字數據。尚不支持此參數。
- dropna:布爾值,默認為真
不要包括 NaN 和 None 的計數。
- result:包含唯一值計數的係列。
參數:
返回:
例子:
>>> import cudf >>> sr = cudf.Series([1.0, 2.0, 2.0, 3.0, 3.0, 3.0, None]) >>> sr 0 1.0 1 2.0 2 2.0 3 3.0 4 3.0 5 3.0 6 <NA> dtype: float64 >>> sr.value_counts() 3.0 3 2.0 2 1.0 1 dtype: int32
可以通過傳遞
ascending=True
來更改計數的順序:>>> sr.value_counts(ascending=True) 1.0 1 2.0 2 3.0 3 dtype: int32
normalize
設置為 True,通過將所有值除以值的總和來返回相對頻率。>>> sr.value_counts(normalize=True) 3.0 0.500000 2.0 0.333333 1.0 0.166667 dtype: float64
要包括
NA
值計數,請傳遞dropna=False
:>>> sr = cudf.Series([1.0, 2.0, 2.0, 3.0, None, 3.0, 3.0, None]) >>> sr 0 1.0 1 2.0 2 2.0 3 3.0 4 <NA> 5 3.0 6 3.0 7 <NA> dtype: float64 >>> sr.value_counts(dropna=False) 3.0 3 2.0 2 <NA> 2 1.0 1 dtype: int32
相關用法
- Python cudf.Series.var用法及代碼示例
- Python cudf.Series.ceil用法及代碼示例
- Python cudf.Series.update用法及代碼示例
- Python cudf.Series.max用法及代碼示例
- Python cudf.Series.head用法及代碼示例
- Python cudf.Series.reindex用法及代碼示例
- Python cudf.Series.interleave_columns用法及代碼示例
- Python cudf.Series.min用法及代碼示例
- Python cudf.Series.nlargest用法及代碼示例
- Python cudf.Series.to_frame用法及代碼示例
- Python cudf.Series.mask用法及代碼示例
- Python cudf.Series.notnull用法及代碼示例
- Python cudf.Series.isnull用法及代碼示例
- Python cudf.Series.rmod用法及代碼示例
- Python cudf.Series.map用法及代碼示例
- Python cudf.Series.nsmallest用法及代碼示例
- Python cudf.Series.data用法及代碼示例
- Python cudf.Series.lt用法及代碼示例
- Python cudf.Series.product用法及代碼示例
- Python cudf.Series.add用法及代碼示例
注:本文由純淨天空篩選整理自rapids.ai大神的英文原創作品 cudf.Series.value_counts。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。