Search code examples
pythonpandasany

How to check if is there a value in a dataframe


I would like to check if is there any value different than zero and different than NaN in a dataframe column. I was using the following method but is not working quite right now.

if ts.any((ts['x'] > 0) || (ts['x'] < 0)):
   bool = True

or

if ts.any((ts['x'] > 0) || (ts['x'] < 0)):
   bool = True

Any tips of how should I proceed ?


Solution

  • Use | for bitwise OR or & for bitwise AND with any:

    if ((ts['x'] > 0) | (ts['x'] < 0)).any():
    

    Or:

    if ((ts['x'] != 0) & (ts['x'].notnull())).any():