[Solved] Openpyxl & Python : column of keys, column of values – how to add up the values and assign totals to corresponding keys

Try this code: # Define a dict{} for key:value pairs ref_total = {} # Get Data from all rows for row in ws.rows: # Slice cells A,B from row tuple cell_A = row[:1][0] cell_B = row[1:2][0] reference = cell_A.value if reference in ref_total.keys(): ref_total[reference] += cell_B.value else: ref_total[reference] = cell_B.value for key in sorted(ref_total.keys()): print(‘%s … Read more

[Solved] convert dictionary into xls file using python openpyxl library

import csv one_year_reserved = { ‘australia-central’: 0.0097, ‘usgov-virginia’: 0.00879, ‘us-south-central’: 0.00731, ‘france-south’: 0.01119, ‘us-west’: 0.00719, ‘europe-north’: 0.00822, ‘asia-pacific-east’: 0.0097, ‘japan-east’: 0.00799, ‘west-india’: 0.00833, ‘united-kingdom-west’: 0.00685, ‘usgov-arizona’: 0.00879, ‘brazil-south’: 0.00982, ‘australia-east’: 0.00776, ‘us-west-2’: 0.00605, ‘asia-pacific-southeast’: 0.00776, ‘south-india’: 0.01005, ‘us-central’: 0.00731, ‘us-east-2’: 0.00605, ‘south-africa-west’: 0.01016, ‘canada-central’: 0.00674, ‘south-africa-north’: 0.00811, ‘canada-east’: 0.00685, ‘us-east’: 0.00605, ‘korea-south’: 0.00639, ‘united-kingdom-south’: 0.00685, … Read more