2013-05-10 30 views

cevap

16

ben sadece 0'a değerleri karşılaştırmak ve .all() kullanırsınız: Değerler sadece

>>> df = pd.DataFrame(np.random.randint(0, 2, (2, 8))) 
>>> df 
    0 1 2 3 4 5 6 7 
0 0 0 0 1 0 0 1 0 
1 1 1 0 0 0 1 1 1 
>>> df == 0 
     0  1  2  3  4  5  6  7 
0 True True True False True True False True 
1 False False True True True False False False 
>>> (df == 0).all() 
0 False 
1 False 
2  True 
3 False 
4  True 
5 False 
6 False 
7 False 
dtype: bool 
>>> df.columns[(df == 0).all()] 
Int64Index([u'2', u'4'], dtype=int64) 
>>> df.loc[:, (df == 0).all()] 
    2 4 
0 0 0 
1 0 0 
+0

yana '0' ve' 1'. Df.loc [:, (~ df.astype (bool)). All()] 'da kullanabilirsiniz. – Zero

İlgili konular