pyspark.pandas.Index.nunique ¶
-
Index.
nunique
( dropna : bool = True , approx : bool = False , rsd : float = 0.05 ) → int ¶ -
返回对象中唯一元素的数量。 默认情况下排除NA值。
- Parameters
-
- dropna bool, default True
-
不要在计数中包含NaN。
- approx: bool, default False
-
如果为 False,将使用精确算法并返回精确的唯一值数量。 如果为 True,则使用 HyperLogLog 近似算法,该算法在处理大量数据时显著更快。 注意:此参数是 pandas-on-Spark 特有的,在 pandas 中找不到。
- rsd: float, default 0.05
-
HyperLogLog算法中允许的最大估计误差。 注意:与
approx
一样,此参数是pandas-on-Spark特有的。
- Returns
-
- int
另请参阅
-
DataFrame.nunique
-
DataFrame 的 nunique 方法。
-
Series.count
-
计算Series中的非NA/null观测值数量。
示例
>>> ps.Series([1, 2, 3, np.nan]).nunique() 3
>>> ps.Series([1, 2, 3, np.nan]).nunique(dropna=False) 4
在大数据上,我们建议使用近似算法来加速此功能。结果将非常接近精确的唯一计数。
>>> ps.Series([1, 2, 3, np.nan]).nunique(approx=True) 3
>>> idx = ps.Index([1, 1, 2, None]) >>> idx Float64Index([1.0, 1.0, 2.0, nan], dtype='float64')
>>> idx.nunique() 2
>>> idx.nunique(dropna=False) 3