dimanche 8 décembre 2019

How to use column values in Python user define function?

I want to check values of a column inside a user defined function, if the column has value 1 it will return 1 and if the value is 0 it will return a 0. Then, I wanted to create a new column with these values

def count_developer(x): 
    if ['datascientist'] == "1":
        return 1 
    else:
        return 0
    dat2['count_developer'] = dat2.apply(count_developer,axis=1)

but, I am getting only "0" as value in the newly created column "count_developer", though the column "datascientist" has both 0 and 1 as value

Aucun commentaire:

Enregistrer un commentaire