lundi 14 décembre 2020

Python equivalent for Rowsums

enter image description here

Sample data

I have a R-code and I wanted to convert it to a similar python code. This is the R code snippet:

data$total <- ifelse(data$dpd_gt_30 == 1 , rowSums(data[0:2]),
                 ifelse(data$dpd_gt_30 == 3 , rowSums(data[2:4]),1000))

What I am doing :

data['total']=data.iloc[:, 0:2].sum(axis=1).where(data['dpd_gt_30'] == 1,1000)

How do I add multiple (more than 2 if required) conditions to this?

Aucun commentaire:

Enregistrer un commentaire