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.