- Posts: 12
- Thank you received: 0
Ask the community, share ideas, and connect with other LimeSurvey users!
method = "get_question_properties" for i in surveyIDs: # surveyIDs is a list of the surveyIDs the user has access to # 'questions[i]' is a dataframe containing the results of a 'list_questions' query questions[i]['answeroptions'] = None # add column for answeroptions for index, row in questions[i].iterrows(): # for each question ID, we need to make a new API call row['answeroptions'] = api.query(method=method, params=OrderedDict([ ("sSessionKey", api.session_key), ("iQuestionID", row['qid']), ("aQuestionSettings", ['answeroptions']) ]))['answeroptions'] if row['answeroptions'] == 'No available answer options': # if no answer options are provided, we try to use the parent's answer options (e.g. array questions) try: row['answeroptions'] = questions[i][questions[i]['qid']==row['parent_qid']]['answeroptions'].reset_index(drop=True)[0] except: row['answeroptions'] = None # if this fails too (usually means there is no parent, and the question is not a real question), set it to None