1

I have an excel spreadsheet as follows:

data = pd.read_excel(r'survey.xlsx')

Each row is a response to a survey, with columns being the different questions in Likert scale (Strong Agree, Mostly Agree, Neutral, Mostly Disagree, Strong Disagree).

Let's say that for a given question, the survey information in the excel spreadsheet can be printed as

print(data.iloc[:,9])

which gives

0                  Mostly Agree
1                  Mostly Agree
2               Mostly Disagree
3    Neither Agree Nor Disagree
4                Strongly Agree

I would like to use this package:

https://github.com/nmalkin/plot-likert

(or any other package for Likert scale)

to print a Likert graph (as in the repos showing) for all the survey questions.

I am specifically confused about this piece of code there which seems to do the work:

# Make sure you have some data
import pandas as pd

data = pd.DataFrame({'Q1': {0: 'Strongly disagree', 1: 'Agree', ...},
                     'Q2': {0: 'Disagree', 1: 'Strongly agree', ...}})

# Now plot it!
import plot_likert

plot_likert.plot_likert(data, plot_likert.scales.agree, plot_percentage=True);

and specifically, how to copy the data from the spreadsheet (which I also use Pandas for) into the "DataFrame". I am also not sure how to change 'Q1', 'Q2' in the Dataframe into the actual question, taking from the column header in the spreadsheet.

If any help could be given with that, I would greatly appreciate that.

My question is: given the spreadsheet in the above format (where several columns consist of questions, for example Column J asks "The movie was fun" with responses in each row with text "Strongly agree" etc.) how do I reformat it into a dataframe such as (where I can input the indices of the columns in the spread in a list list_questions = [9, 12, 17] etc):

data = pd.DataFrame({'Q1': {0: 'Strongly disagree', 1: 'Agree', ...},
                     'Q2': {0: 'Disagree', 1: 'Strongly agree', ...}})
kloop
  • 4,537
  • 13
  • 42
  • 66
  • What actually is your question? The bit at the end makes it seem like you want to open an `xls` into a dataframe, but at the top you show that you're already doing that. The `plot_likert` part seems to be unconnected to your problem. – defladamouse Dec 02 '21 at 16:30
  • I tried to sharpen my question... I am having trouble translating between the data in the spreadsheet and the DataFrame object for the Likert scale. – kloop Dec 02 '21 at 16:59
  • I think you need to sharpen it a lot more. As far as I can tell, the Likert scale has nothing to do with your problem, so strip all of that out, give an example of what your data looks like and just focus on the bit you're struggling with - getting it into a suitable dataframe. – defladamouse Dec 02 '21 at 18:16

1 Answers1

1

If you have your questions and would like to make a Likert-Chart out of the data you can convert your unique values for each question into a dictionary.

create the response associated with the survey

NOTE
You may have to change your scale to match the python package requirements

questions_response = {
    1:"Strongly Disagree",
    2:"Disagreee",
    3:"Neutral",
    4:"Agree",
    5:"Strongly Agree"
}

Create a loop of the columns and append a Dictionary

This is making an assumption that you may have more than one survey question that use the same scale

questionaire = dict()

for question in questions:
    questionaire[question]=questions5_response

Create you Pandas DataFrame

Convert the dictionary to a DataFrame

data = pd.DataFrame(questionaire)

plot_likert.plot_likert(data, plot_likert.scales.agree, plot_percentage=True)
Brandon
  • 1,036
  • 2
  • 17
  • 19