dimanche 29 mars 2020

Python - Pandas: IF statement based on column values

I am trying to develop an IF statement, which will - Run another python script, if there are values in [Column Name] which are equal to zero. - Else do nothing.

My original thought was to do something like

if df['column name'] == 0:

subprocess.call("python script.py", shall = True)

else:

print('No values of 0')

This gives me the following error: ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().

If I try to specify any of these I am not really getting what I want.

To be specific I want the script to iterate over the values of a specific column and see if any of these values are = 0 and if they are I want to run another script which sends me an email warning.

Sorry if this has already been explained elsewhere but i cannot find it.

I am on Python 3.7.5 and using pandas.

Thank you for the help

Aucun commentaire:

Enregistrer un commentaire