pandas 之 value_counts(), unique()

.value_counts() 统计不同值的个数,不包括 NaNunique() 用来展示每个不同的值,包括 NaN

test = pd.DataFrame({'a': [1, 1, np.NaN, 2, 3],
                  'b': [1, 2, 3, 4, 5],
                  'c': np.random.randn(5)})

test['a'].value_counts()
## output
1.0    2
3.0    1
2.0    1
Name: a, dtype: int64

test['a'].unique()
## output
array([ 1., nan,  2.,  3.])

猜你喜欢

转载自blog.csdn.net/guo_ya_nan/article/details/81020264