0

I've having an issue checking is a value is in the following dataframe:

index open high SignalEMA25M50M PositionEMA25M50M
2021-03-30 05:35:00 0.000059 0.000059 0 -1.0
2021-03-30 05:40:00 0.000059 0.000059 0 0.0
2021-03-30 05:45:00 0.000059 0.000059 0 0.0

i am trying to simply return true if the PositionEMA25M50M contains -1.0

i have tried:

if -1.0 in indicator_5min_df.PositionEMA25M50M:
    print('true')
else:
    print('false')

however this returns false every time... i assume this is something to do with PositionEMA25M50M being of type float64 however i've also tried

if np.float64(-1.0) in indicator_5min_df.PositionEMA25M50M:
    print('true')
else:
    print('false')

which has given me the same result...

any ideas how i can fix this?

user1133512
  • 89
  • 2
  • 7

1 Answers1

1

You don't need a if loop. You can directly use Series.eq with any to check if any row has -1 for this column:

In [990]: df['PositionEMA25M50M'].eq(-1).any()
Out[990]: True
Mayank Porwal
  • 33,470
  • 8
  • 37
  • 58
  • dupe https://stackoverflow.com/questions/21319929/how-to-determine-whether-a-pandas-column-contains-a-particular-value – jezrael Mar 30 '21 at 06:38