DIRKMJK / limepy

Download and summarise LimeSurvey data
MIT License
24 stars 8 forks source link

Getting a KeyError: 'help' when creating survey object #16

Closed dbclinton closed 2 years ago

dbclinton commented 2 years ago

Hi, I manually downloaded my CSV using Question code and Answer codes as settings and used your sample code to build my survey object:

df = pd.read_csv('code-results-survey543837.csv', sep=';')
with open('limesurvey_survey_872183.lss') as f:
    my_structure = f.read()
my_survey = Survey(df, my_structure)

But the my_survey object is failing. Here's the traceback:

KeyError                                  Traceback (most recent call last)
/tmp/ipykernel_824/587664489.py in <module>
      3     my_structure = f.read()
      4 
----> 5 my_survey = Survey(df, my_structure)
~/.local/lib/python3.8/site-packages/limepy/wrangle.py in __init__(self, dataframe, structure, language, strip_tags)
     52         self.language = language
     53         self.strip_tags = strip_tags
---> 54         self.questions, self.groups = self.parse_structure(structure)
     55         self.question_list = self.create_question_list()
     56         self.readable_df = self.create_readable_df()
~/.local/lib/python3.8/site-packages/limepy/wrangle.py in parse_structure(self, structure)
    108                 if item['language'] == language
    109             }
--> 110             question_l10ns_help = {
    111                 item['qid']:item['help']
    112                 for item
~/.local/lib/python3.8/site-packages/limepy/wrangle.py in <dictcomp>(.0)
    109             }
    110             question_l10ns_help = {
--> 111                 item['qid']:item['help']
    112                 for item
    113                 in items
KeyError: 'help'

Any idea what I'm doing wrong? Thanks!

DIRKMJK commented 2 years ago

Thanks for your feedback. As a first check - is the delimiter (sep=';') consistent with the delimiter in the csv file?

dbclinton commented 2 years ago

I tried it both ways (either setting the delimiter in both the data itself and the code to , or ;) and got the same KeyError. Thanks!

DIRKMJK commented 2 years ago

Hi, I think the problem might be that this key isn’t present in the .lss file if none of the questions have a help text. I’ve uploaded a new version; could you check if this solves the problem? Thanks

dbclinton commented 2 years ago

Yup. That definitely worked. Thanks so much!