jeudi 19 mars 2015

Python Pandas Use if-else to populate new column

I have a data set like this:



col1 col2
1 0
0 1
0 0
0 0
3 3
2 0
0 4


I'd like to add a column that is a 1 if col2 is > 0 or 0 otherwise. If I was using R I'd do something like



df1[,'col3'] <- ifelse(df1$col2 > 0, 1, 0)


How would I do this in python / pandas?


Aucun commentaire:

Enregistrer un commentaire