mardi 15 octobre 2019

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

I am using this piece of code for a if statement:

for col in df2.columns:
    a = np.array(df2[col])
    p98 = stats.scoreatpercentile(a, 98)
    p5 = stats.scoreatpercentile(a, 5)
    maxv = df2.max(axis=0)
    minv = df2.min(axis=0)
    ratiomax = maxv/p98
    print(ratiomax)
    ratiomin = minv/p5
    print(ratiomin)

    if (ratiomax <= 1.1).bool() == True:
        maxv = maxv
    else: maxv = p98

    if ratiomin <= 0.2:
        minv = minv
    else: minv = 95

Neither type of if statement are working and throwing the error:

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

The solutions given earlier on this error are np.where and choosing selective values from dataframe but mine is about if statement.

Please help.

Thanks

Aucun commentaire:

Enregistrer un commentaire