Chocolate nutrient comparison

import numpy as np from sklearn.preprocessing import MinMaxScaler # name, energy (kJ), protein (g), fat total (g), fat saturated (g), carbohydrates (g), sugars (g), sodium (mg) (in 100g) lindt_excellence_chocolates = """ Raspberry Intense,2180,5.2,31.0,18.0,51.0,49.0,35 Lime Intense,2161,6.0,31.0,18.0,50.0,48.0,12 Arabica,2180,5.2,32.0,19.0,49.0,47.0,35 Madagascar,2520,4.8,50.0,31.0,31.0,29.0,42 Mild 70%,2528,6.9,48,29,33,29,19 Cocoa 99%,2433,15,51,30,8,1,25 Coconut Intense,2224,5.1,34.0,22.0,47.0,46.0,35 Grapefruit 100g,2128,5.5,29,18,53,51,90 Cocoa 70%,2350,9.5,41,24,34,29,39 Cocoa 90%,2483,10,55,30,14,7,30 Cocoa 85%,2413,12.5,46,28,19,14,10 Sea Salt,2205,6.2,32,20,50,48,31 Mint,2202,5,32,19,51,49,35 Caramel & Sea Salt,2117,4.6,28,17,55,54,145 Orange Intense,2193,6.7,32,18,49,42,36 Chili,2240,6.1,33,20,50,48,41 Extra Creamy,2387,6.4,37,23,51,50,114 """ ritter_sport_chocolates = """ 250g White + Crisp,2244,5.2,30,19,62,53,48 250g Hazelnuts,2323,7.3,35,17,52,51,17 250g Cornflakes,2224,5.9,30,18,59,50,40 250g Praline,2336,7.4,35,15,53,51,130 250g Alpine Milk Chocolate,2283,8.1,32,19,55,54,170 White Whole Hazelnuts,2427,7.9,40,16,48,44,220 Whole Hazelnuts,2397,8.6,39,16,46,44,150 Macadamia,2417,8.3,39,17,47,45,150 Whole Almonds,2330,9.7,37,14,45,44,150 Dark Whole Hazelnuts,2395,8.4,41,16,39,37,0 Honey Salt Almonds,2349,8.9,35,15,51,48,270 White + Crisp,2244,5.2,30,19,62,53,480 Raisins Hazelnuts,2142,6.2,28,15,56,55,150 Rum Raisins Hazelnuts,2155,6.1,28,15,55,54,160 Praline,2334,7.4,35,15,53,51,130 Marzipan,2060,6.7,27,11,53,51,0 Coconut,2468,6.7,41,22,48,47,180 Cornflakes,2173,6.5,27,16,60,50,430 Yogurt,2392,7.6,38,22,49,48,280 Biscuits + Nuts,2261,7.2,32,17,55,50,360 Peppermint,2060,3.5,27,18,58,52,30 Hazelnuts,2323,7.3,35,17,52,51,170 Butter Biscuit,2315,6,34,20,56,48,340 Cocoa Mousse,2404,7.4,39,23,47,46,270 Dark Chocolate,2224,6,33,19,50,48,0 Espresso,2402, 5.9,39,32,48,47,180 Strawberry Yogurt,2356,5.4,37,22,52,51,210 Fine Milk Chocolate,2356,6.5,36,22,52,52,190 Fine Extra Dark Chocolate,2497,8.7,49,29,25,23,10 Alpine Milk Chocolate,2283,8.1,32,19,55,54,170 Caramel Mousse,2451,6.3,41,23,49,45,340 White Hazelnuts,2377,6.3,36,19,54,52,240 Buttermilk Lemon,2410,7,38,22,50,50,180 Cocoa Creme,2501,6.5,44,25,42,41,160 Raspberry Creme,2394,5.3,38,22,52,50,170 """ chocolates = [lindt_excellence_chocolates, ritter_sport_chocolates] names, data = [], [] for chocolate in chocolates: items = chocolate[1:-1].split('\n') for item in items: name, energy_kj, protein_g, fat_total_g, fat_saturated_g, carbohydrates_g, sugars_g, sodium_mg = item.split(',') data_values = energy_kj, protein_g, fat_total_g, fat_saturated_g, carbohydrates_g, sugars_g, sodium_mg data_values = [float(dv) for dv in data_values] names.append(name) data.append(data_values) data = np.array(data) # Which five chocolates give the most energy and protein with the least fats, sugars and sodium? data[:,2:] = 1 - data[:,2:] mms = MinMaxScaler() transformed = mms.fit_transform(data) scores = np.sum(transformed, axis=1) sorted_indices = scores.argsort() top_indices = np.argwhere(sorted_indices < 5).ravel() print(np.array(names)[top_indices]) # ['Whole Almonds', 'Dark Whole Hazelnuts', 'Marzipan', 'Coconut', 'Strawberry Yogurt']