2016-04-07 31 views

回答

2

是的,你可以使用unique()爲:

In [35]: w 
Out[35]: 
    word 
0 word03 
1  NaN 
2 word04 
3 
4 word02 
5 word01 
6  NaN 
7 word01 
8 word01 
9 word01 

In [36]: w.word.unique() 
Out[36]: array(['word03', nan, 'word04', '', 'word02', 'word01'], dtype=object) 

所以用套,我們可以看到允許/預期的字符串和字符串之間的區別在DF:

In [45]: allowed_words = set(['','word01', np.nan]) 

In [46]: set(w.word.unique()) - allowed_words 
Out[46]: {'word02', 'word03', 'word04'} 
相關問題