I'm trying to obtain the most common asnwers so we have Yes/No questions and it has i eleven questions from this one I would like to know from Yes/No which was has most answers as an example:
If in more than the half of the eleven i's has No>Yes the most common answers will be 'NO' but I'm not really sure what function I need to do this, comparing the rows 0 and 1 to know which one had more answers.
I would like to do this kind of script:
CodePudding user response:
To obtain a list of 'yes' and 'no' you can do:
no_count = df.iloc[0].values[1:]
yes_count = df.iloc[1].values[1:]
most_common = ['no' if no_count[i]>yes_count[i] else 'yes' for i in range(len(no_count))]
Then you can count the number of each
number_no = most_common.count("no")
number_yes = most_common.count("yes")