Equivalent of R/ifelse in Python/Pandas? Compare string columns?

You have to upgrade pandas to last version, because in version 0.17.1 it works very well.

Sample (first value in column install_month is changed for matching):

print maupayment
  log_month  user_id install_month  payment
1   2013-06        1       2013-06        0
2   2013-06        2       2013-04        0
3   2013-06        3       2013-04    14994

print np.where(maupayment['log_month'] == maupayment['install_month'], 'install', 'existing')
['install' 'existing' 'existing']

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)