Change column values in pandas df under different conditions / invert answers on 4-point likert-scale

You could use .replace(), but I think this solution is more fun 🙂

questDay1Df['STAI_State_01'] = np.abs(questDay1Df['STAI_State_01'] - 5)

The .replace() possibility is more widely applicable:

questDay1Df['STAI_State_01'] = questDay1Df['STAI_State_01'].replace({
    1: 4, 
    2: 3, 
    3: 2, 
    4: 1,
})

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top