unique()函数

unique()函数可输出列表,元组和series中的不同元素。

且只能输出dataframe的某一列series中的不同元素,不能同时输出。

返回的都是一个ndarry,但不能输出ndarry中的不同元素,即对ndarry无效。

 1 A = [1, 2, 2, 5,3, 4, 3]
 2 a = np.unique(A)
 3 B= (1, 2, 2,5, 3, 4, 3)
 4 b= np.unique(B)
 5 C= ['fgfh','asd','fgfh','asdfds','wrh']
 6 c= np.unique(C)
 7 d = df['列名'].unique()
 8 print(a)
 9 print(b)
10 print(c)
11 print(date_received)
12 # [1 2 3 4 5]
13 # [1 2 3 4 5]
14 # ['asd' 'asdfds' 'fgfh' 'wrh']
15 # ['20160113' '20160108' '20160115' '20160513' '20160208' 
16 #  '20160310' '20160307' '20160221' '20160226' '20160309']

 

参考: https://blog.csdn.net/yangyuwen_yang/article/details/79193770

猜你喜欢

转载自www.cnblogs.com/xxswkl/p/10861624.html