with open('names.csv', 'w') as csvfile:
    fieldnames = ['first_name', 'last_name']
writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
writer.writeheader()
writer.writerow({'first_name': 'Baked', 'last_name': 'Beans'})
How do I convert this list of dictionaries to a csv file? [Python]