Print string in pandas if any value in string is zero

How to reset a string if any of the values ​​in the string is zero?

I would normally use df.dropna () for NaN values, but not sure how to do this with the values ​​"0".

+7
python pandas
source share
2 answers

I think the easiest way is to look at the lines where all values ​​are not 0:

df[(df != 0).all(1)] 
+11
source share

You can create a boolean frame and then use any :

 >>> df = pd.DataFrame([[1,0,2],[1,2,3],[0,1,2],[4,5,6]]) >>> df 0 1 2 0 1 0 2 1 1 2 3 2 0 1 2 3 4 5 6 >>> df == 0 0 1 2 0 False True False 1 False False False 2 True False False 3 False False False >>> df = df[~(df == 0).any(axis=1)] >>> df 0 1 2 1 1 2 3 3 4 5 6 
+11
source share

All Articles