Reverse Scoring in Python

When working with questionnaires that use a Likert scale (e.g., strongly disagree, disagree, neutral, agree, strongly agree) we sometimes want to reverse the scoring.  For instance, in a questionnaire subjective experiences of cognition some of the questions can be positively worded (e.g., “I find it easy to read while talking in the telephone at the same time”). However, we often have questions that are negatively worded (e.g., “When there is music in the room I find it hard to concentrate on reading”).

In the case of positively worded questions we can score them like this; strongly disagree with a score of 1, disagree= 2, neutral =3, agree = 4 and strongly disagree =5. However, the same scoring can’t be applied for the negatively worded questions. We now need to reverse the score of these questions.  In the python example below, score 5 becomes 1, 4 becomes 2, 2 becomes 4 and 1 becomes 5. Three, on the other hand, (neutral) stays the same.

The following Python example uses Pandas DataFrame. If you need to learn more about Pandas check out my dataframe tutorial.

Reverse scoring in Python:

In ths reverse scoring with Python example we are generating some data. Typically, we have collected data using an instrument and the data can be either in Excel (e.g., xlsx) or CSV format. If you need to learn more about loading Excel to Dataframes see my Pandas read_excel guide.

With Pandas DataFrame you can easily save your new dataframe to .csv-file. I use ‘;’ as separator (‘,’ is more commonly used):

That is it! Pretty simple to reverse scores in Python. Now you can continue with your analysis.

Update: If you are using R I have written a short script on how to reverse scores using that language: Reverse scoring in R statistical programming environment

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.