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

Time:09-13

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...

CodePudding user response:

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()
  • Related