- 用法:- Index.value_counts(normalize=False, sort=True, ascending=False, bins=None, dropna=True)
- 返回一個包含唯一值計數的係列。 - 結果對象將按降序排列,因此第一個元素是最多的 frequently-occurring 元素。默認情況下排除 NA 值。 - normalize:布爾值,默認為 False
- 如果為 True,則返回的對象將包含唯一值的相對頻率。 
- sort:布爾值,默認為真
- 按頻率排序。 
- ascending:布爾值,默認為 False
- 按升序排列。 
- bins:整數,可選
- 與其計數值,不如將它們分組到半開箱中,這對 - pd.cut很方便,僅適用於數字數據。
- dropna:布爾值,默認為真
- 不包括 NaN 的計數。 
 
- Series
 
 - 參數:- 返回:- 例子:- >>> index = pd.Index([3, 1, 2, 3, 4, np.nan]) >>> index.value_counts() 3.0 2 1.0 1 2.0 1 4.0 1 dtype:int64- 將 - normalize設置為- True時,通過將所有值除以值的總和來返回相對頻率。- >>> s = pd.Series([3, 1, 2, 3, 4, np.nan]) >>> s.value_counts(normalize=True) 3.0 0.4 1.0 0.2 2.0 0.2 4.0 0.2 dtype:float64- 箱子 - 箱對於從連續變量到分類變量很有用;而不是計算值的唯一幻影,而是將索引劃分為指定數量的半開箱。 - >>> s.value_counts(bins=3) (0.996, 2.0] 2 (2.0, 3.0] 2 (3.0, 4.0] 1 dtype:int64- dropna - 將 - dropna設置為- False我們還可以看到 NaN 索引值。- >>> s.value_counts(dropna=False) 3.0 2 1.0 1 2.0 1 4.0 1 NaN 1 dtype:int64
相關用法
- Python pandas.Index.argmin用法及代碼示例
- Python pandas.Index.is_categorical用法及代碼示例
- Python pandas.Index.to_series用法及代碼示例
- Python pandas.Index.str用法及代碼示例
- Python pandas.Index.to_numpy用法及代碼示例
- Python pandas.Index.is_object用法及代碼示例
- Python pandas.Index.slice_indexer用法及代碼示例
- Python pandas.Index.is_interval用法及代碼示例
- Python pandas.Index.notnull用法及代碼示例
- Python pandas.Index.equals用法及代碼示例
- Python pandas.Index.set_names用法及代碼示例
- Python pandas.Index.searchsorted用法及代碼示例
- Python pandas.Index.duplicated用法及代碼示例
- Python pandas.Index.is_monotonic_increasing用法及代碼示例
- Python pandas.Index.min用法及代碼示例
- Python pandas.Index.is_monotonic_decreasing用法及代碼示例
- Python pandas.Index.max用法及代碼示例
- Python pandas.Index.shift用法及代碼示例
- Python pandas.Index.argmax用法及代碼示例
- Python pandas.Index.any用法及代碼示例
注:本文由純淨天空篩選整理自pandas.pydata.org大神的英文原創作品 pandas.Index.value_counts。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
