jeudi 22 juillet 2021

IF statement error with checking column condition

I have a dataframe below and want to check every number by column with a certain condition.

import pandas as pd
df = pd.DataFrame([[10,3,1], [3,7,2], [2,4,4]], columns=list("ABC"))

If any one cell in the columns meets the certain condition by column. I will then execute some codes accordingly.

if (df['A'] > 8) | (df['B'] > 6) | (df['C'] > 5):
   print(df.loc[: 'A']) #print function here is just an example

The error message says:

alueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().

How can I solve my IF statement to execute the Print code?

Aucun commentaire:

Enregistrer un commentaire