lundi 31 mai 2021

I have got a problem checking a condition and write the answer into a new column

I have a column called "score_differential". I want to write a "1" into the new column "home_win" if the number is positive and a "0" if the number is negative. Result is the name of my new DataFrame.

This is my try

result.loc[i,"home_win"]=if result["score_differential"] > 0:
                                print("1")
                                else:
                                    print("0")

But this gives me the error "invalid_syntax". I am new to python so thanks for any help.

Aucun commentaire:

Enregistrer un commentaire