from pandas import Series,DataFrame
import pandas as pd
obj = Series(['c','a','d','a','a','b','b','c','c'])
obj
0 c
1 a
2 d
3 a
4 a
5 b
6 b
7 c
8 c
dtype: object
.unique() 得到唯一值数组,未排序
obj.unique()
array(['c', 'a', 'd', 'b'], dtype=object)
.value_counts() 计算Series中各值出现的频率,按值频率降序排列
obj.value_counts()
c 3
a 3
b 2
d 1
dtype: int64
obj.values
array(['c', 'a', 'd', 'a', 'a', 'b', 'b', 'c', 'c'], dtype=object)
pd.value_counts(obj.values,sort=False)
a 3
d 1
b 2
c 3
dtype: int64
isin() 计算一个表示“Series各值是否包含于传入的值序列中”的布尔型数组
mask = obj.isin(['b','c'])
mask
0 True
1 False
2 False
3 False
4 False
5 True
6 True
7 True
8 True
dtype: bool
obj[mask]
0 c
5 b
6 b
7 c
8 c
dtype: object