mardi 27 août 2019

Assign variable value in pandas dataframe with for loop

I'm a python beginner and I'd like to assign a value to a variable in a data frame if some conditions are satisfied:

df['clou']=0
for row in df.itertuples():
    if row.Team=='Q' and row.OPP=='W': row.clou=1
    elif row.Team=='M' and row.OPP=='A': row.clou=1
    else : row.clou=0 

but I obtain this error: AttributeError: can't set attribute Team,OPP and clou are variables of the data.frame

Can anyone help me?

Aucun commentaire:

Enregistrer un commentaire