Hey I am working with Qualtircs data I am having trouble coming up with the logic form returning the selected answers my each user. There is a choice dict that shows all the answers that a user can select and I made a key that displays the users selection.
Right now my code only looks for one answers and continues. My issue is some of the question are "select all that apply" This is the choice dict:
{'QID1_1': 'John', 'QID1_2': 'Dan', 'QID1_3': 'Joshua', 'QID2_1': 'Atlanta', 'QID2_2': 'Norfolk', 'QID2_3': 'Miami', 'finished_0': 'False', 'finished_1': 'True', 'status_0': 'IP Address', 'status_1': 'Survey Preview', 'status_2': 'Survey Test', 'status_4': 'Imported', 'status_8': 'Spam', 'status_9': 'Survey Preview Spam', 'status_12': 'Imported Spam', 'status_16': 'Offline', 'status_17': 'Offline Survey Preview', 'status_32': 'EX', 'status_40': 'EX Spam', 'status_48': 'EX Offline'}
My snippet of code that works with the one selection
mapped_list = {}
for row in response_dict:
if row["resp_md_key"] not in column_list:
continue
response_id = row["response_id"]
if response_id not in mapped_list:
mapped_list[response_id] = {}
# Check if Multichoice and retrieve MC value if needed
key = f'{row["resp_md_key"]}_{row["response_value"]}'
if key in choice_dict:
value = choice_dict[key]
else:
value = row["response_value"]
if isinstance(value, str):
if "'" in value:
value = value.replace("'", "\\'")
mapped_list[response_id][row["resp_md_key"]] = f"'{value}'"
else:
mapped_list[response_id][row["resp_md_key"]] = value