Checking that ALL rows have met a certain criteria in a dataframe using iLoc

82 Views Asked by At

I need to make sure that ALL the rows have met a certain criteria not just some of them..

I have this code which returns TRUE when some of the rows meet the criteria..

Any idea how to only return TRUE when all the rows meet the criteria??

Thanks

  if position == -1:

if ((df.iloc[-rows]['ABC']) < level ):

  return True
else:
  return False

  elif position == 1:

if ((df.iloc[-rows]['ABC']) > level ):

  return True
else:
  return False

position, level and rows are parameters from a function...

1

There are 1 best solutions below

3
Tom McLean On BEST ANSWER

Just remove the .iloc[-rows] part and use .all()

if position == -1:
  return (df["ABC"] < level).all()
elif position == 1:
  return (df["ABC"] > level).all()