Skip to content

Instantly share code, notes, and snippets.

@hrisheekeshr
Created June 27, 2018 12:57
Show Gist options
  • Save hrisheekeshr/346f6c7f82315baa88bc9ab7d49ed4c9 to your computer and use it in GitHub Desktop.
Save hrisheekeshr/346f6c7f82315baa88bc9ab7d49ed4c9 to your computer and use it in GitHub Desktop.
def calculate_good_bad_average(data):
result = data.groupby(['Competency','Status'])['Status'].count()
keys = result.to_dict().keys()
competency= list()
for item in keys:
a = dict()
a = {
"Competency" : item[0],
item[1].lower() : result[item]
}
competency.append(a)
return competency
def get_total_competency_scores(data):
result_list = list()
data = data.groupby(['Competency','Status'])["Status"].count().groupby('Competency').count().to_dict()
for item in data.keys():
result = dict()
result["Competency"]=item
result["No moves"]=data[item]
result["bad"]=int()
result["intermediate"]=int()
result["good"]=int()
result_list.append(result)
return result_list
def main(data):
total_scores = get_total_competency_scores(data)
individual_scores = calculate_good_bad_average(data)
for item_1 in total_scores:
for item_2 in individual_scores:
if item_1['Competency'] == item_2 ['Competency']:
try:
item_1['bad'] = item_2['bad']
item_1['good'] = item_2['good']
item_1['intermediate'] = item_2['intermediate']
except:
try:
item_1['good'] = item_2['good']
item_1['bad'] = item_2['bad']
item_1['intermediate'] = item_2['intermediate']
except Exception as e:
try:
item_1['intermediate'] = item_2['intermediate']
item_1['good'] = item_2['good']
item_1['bad'] = item_2['bad']
except Exception as e:
pass
return total_scores
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment