I'm doing a complex calculation on a data frame that is bound to throw exceptions if all the values in a column are zeros. How to do a quick check whether a column is full of zero? i.e. return True
if the column has values other than 0
else False
.
Asked
Active
Viewed 3.9k times
24

Aakash Parsi
- 93
- 2
- 10

DevEx
- 4,337
- 13
- 46
- 68
-
Can you post sample data? – cmaher Feb 01 '18 at 20:04
1 Answers
46
you can do something like this:
(df['col'] == 0).all()
This will return True if all values are 0 otherwise it will return false
-
1Since you asked for the reverse you can use any() (df[col] != 0).any() – PraveenB Feb 01 '18 at 20:13
-
-
How to retrieve other columns value /id in case it satisfy `df[col]=0.any()` – user1586957 Aug 04 '20 at 01:19
-
Sorry could not understand your question. Could you please elaborate ? – PraveenB Aug 04 '20 at 07:32