lundi 1 novembre 2021

How to edit columns values based on another value?

My data fame looks like this:

val    type
10     new
70     new
61     new
45     old
32     new
77     mid
11     mid

For values in column "type", if value is new, I want to edit it depending on val column. If value in val is =< 20, it must be new-1, if > 20 and < 50, it must be new-2,if >= 50, it must be new-3. So desired result is:

val    type
10     new-1
70     new-3
61     new-3
45     old
32     new-2
77     mid
11     mid

How to do that?

Aucun commentaire:

Enregistrer un commentaire