1

Hello and thank in advance for reading this.

I have a dataframe on which I would like to compare two quantities x and y

def test(x,y) : 

    if x == y :
        return (x,0)

    elif (x > y) :
        off = x - y 
        on = x - off
        return (on, off)
    else : 
        off = y - x
        on = y - off
        return (on, off)

but when I want to apply it to my dataframe

df.apply(lambda x : test(df["quantite_1"], df["quantite_2"]), axis =1)

I have this

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

I understand that something's wrong with the parameters of my function, but I can't tell what. Could someone help me?

0

1 Answer 1

2

The error it's because you're using df["quantite_1"], df["quantite_2"] as parameter, you should use this instead:

df.apply(lambda x : test(x["quantite_1"], x["quantite_2"]), axis =1)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.