pandas.core.resample.Resampler.nunique #
- 最终 重采样器。nunique ( * args , ** kwargs ) [来源] #
返回组中唯一元素的数量。
- 返回:
- 系列
每组内唯一值的数量。
例子
对于系列分组依据:
>>> lst = ['a', 'a', 'b', 'b'] >>> ser = pd.Series([1, 2, 3, 3], index=lst) >>> ser a 1 a 2 b 3 b 3 dtype: int64 >>> ser.groupby(level=0).nunique() a 2 b 1 dtype: int64
对于重采样器:
>>> ser = pd.Series([1, 2, 3, 3], index=pd.DatetimeIndex( ... ['2023-01-01', '2023-01-15', '2023-02-01', '2023-02-15'])) >>> ser 2023-01-01 1 2023-01-15 2 2023-02-01 3 2023-02-15 3 dtype: int64 >>> ser.resample('MS').nunique() 2023-01-01 2 2023-02-01 1 Freq: MS, dtype: int64