Convert csv to json

import json
import os
import csv


os.chdir('/Users/t/PycharmProjects/coronavirus-risk')
print(os.getcwd())

x = {}
with open('area_populations.csv', mode='r') as infile:
    reader = csv.reader(infile)
    for row in reader:
        x[row[1].title()] = {
            'areaCode': row[0],
            'areaType': row[2],
            'population': row[3].replace(',', '')
        }

with open('area_populations.json', mode='w') as file:
    json.dump(x, file)

print(x)

You'll only receive email when they publish something new.

More from T