Hello
I am struggling to understand the code given to us for the function display_table as I get the following error after running this code:
def freq_table(dataset, index):
table = {}
total = 0
for row in dataset:
count_object = row[index]
total += 1
if count_object in table:
table[count_object] += 1
else:
table[count_object] = 1
table_percentages = {}
for key in table:
percentage = (table[key]/total)*100
table_percentages[key] = percentage
return table_percentages
def display_table(dataset, index):
table = freq_table(dataset, index)
table_display = []
for key in table:
key_val_as_tuple = (table[key], key)
table_display.append(key_val_as_tuple)
table_sorted = sorted(table_display, reverse = True)
for entry in table_sorted:
print(entry[1], ':', entry[0])
display_table(google_final,1)
My output is then: