-
Notifications
You must be signed in to change notification settings - Fork 1
/
Questionnaire_analysis.py
141 lines (117 loc) · 4.99 KB
/
Questionnaire_analysis.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
import pandas as pd
import numpy as np
dataframe = pd.read_csv('gamestats18_05v2.csv', ';', names=["participantID", "Section", "QuestionTrial", "Answer", "Time"]) #, sep= ";"
#dataframe = dataframe.split(",", n = 4, expand = True)
print(dataframe)
# #dataframe.columns = ["participantID", "Section", "QuestionTrial", "Answer", "Time"]
#
# print(dataframe)
# #print()
subjects = dataframe.participantID.unique()
subjects = list(set(dataframe.participantID.tolist()))
#print(subjects)
subject_scores_df = pd.DataFrame(columns=["participantID",
"sex",
"age",
"education",
"Score",
"DepressionSeverity"])
for sub in subjects:
current_questions = dataframe.loc[(dataframe["participantID"] == sub) &
(dataframe["Section"] == "Q") &
(dataframe["QuestionTrial"] > 2)]
#print(current_questions)
# Check if subject has answered all the questions
if len(current_questions.index) < 9:
continue
sex = dataframe.loc[(dataframe["participantID"] == sub) &
(dataframe["Section"] == "Q") &
(dataframe["QuestionTrial"] == 0)]
if sex.empty:
sex = "NA"
else:
sex = sex.Answer.values[0]
age = dataframe.loc[(dataframe["participantID"] == sub) &
(dataframe["Section"] == "Q") &
(dataframe["QuestionTrial"] == 1)]
if age.empty:
age = "NA"
else:
age = age.Answer.values[0]
education = dataframe.loc[(dataframe["participantID"] == sub) &
(dataframe["Section"] == "Q") &
(dataframe["QuestionTrial"] == 2)]
if education.empty:
education = "NA"
else:
education = education.Answer.values[0]
#skip our testing triels
if age == 0 and education == 4:
print("Skip that subject!\n")
continue
#calculate the parameters for each partecipants
current_sub_score = current_questions.Answer.sum()
if current_sub_score < 5:
severity = "minimal"
elif current_sub_score < 10:
severity = "moderated"
elif current_sub_score < 15:
severity = "moderately severe"
else:
severity = "severe depression"
if sex == 0:
gender = "male"
elif sex == 1:
gender = "female"
elif sex == 2:
gender = "other"
else:
gender = "prefer not to say"
if age == 0:
Age = "<18"
elif age == 1:
Age = "18-24"
elif sex == 2:
Age = "25-34"
elif sex == 3:
Age = "35-54"
elif sex == 4:
Age = "55-74"
else:
Age = "75+"
if education == 0:
Education = "less then high school diploma"
elif education == 1:
Education = "high school diploma"
elif education == 2:
Education = "bachelor"
elif education == 3:
Education = "master"
else:
Education = "Phd"
subject_scores_df = subject_scores_df.append({'participantID': sub,
'sex': gender,
'age': Age,
'education': Education,
'Score': current_sub_score,
'DepressionSeverity': severity}, ignore_index=True)
print(subject_scores_df)
with pd.option_context('display.max_rows', None, 'display.max_columns', None):
print(subject_scores_df.sort_values('Score', ascending = False))
df = pd.DataFrame(subject_scores_df.sort_values('Score', ascending = False)) #dataFrame sorted by level of depression
print(subject_scores_df['DepressionSeverity']=='moderated')
severe = subject_scores_df.loc[subject_scores_df['DepressionSeverity'] == "severe depression", 'participantID']
moderatelySevere = subject_scores_df.loc[subject_scores_df['DepressionSeverity'] == "moderately severe", 'participantID']
moderated = subject_scores_df.loc[subject_scores_df['DepressionSeverity'] == "moderated", 'participantID']
minimal = subject_scores_df.loc[subject_scores_df['DepressionSeverity'] == "minimal", 'participantID']
severe.to_csv('severeID.csv', index = False, sep =',')
moderatelySevere.to_csv('moderatelySevere.csv', index = False, sep =',')
moderated.to_csv('moderated.csv', index = False, sep =',')
minimal.to_csv('minimal.csv', index = False, sep =',')
#subject_scores_df.to_csv("subject_scores.csv", index=False, sep=";")
#df.to_csv("subject_scores.csv", index=False, sep=";")
#feedback or people
#current_feedback = dataframe.loc[(dataframe["participantID"] == sub) &
# (dataframe["Section"] == "F")]
#print(current_feedback)
#subject_scores_df.set_index(["participantID", "DepressionSeverity"]).count(level="severe depression")