vendredi 8 mai 2020

Python: Print something if none of the if statements in the function are used

I have a function that has several if statements that print "x" if a condition:

I want to write an if statement that if none of the if statements within the function are used print "something"

reproducible example

def my_function(data):
    ### Constant Features Check
    x = pd.DataFrame({'value':data.nunique()})
    for col in x.index:
        if x.loc[col, 'value'] == 1:
            print('Column', col , 'is a constant value')

### lets say i have 100's of "for x in y: if statements "like this 
### If none of are activated i want to print "something"

## if none of the if statements in the for loops print, print(something')

Aucun commentaire:

Enregistrer un commentaire