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

Question:

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…

Asked By: Zak Pinter

||

Answers:

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()
Answered By: Tom McLean
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.