Skip to content

Instantly share code, notes, and snippets.

@brizandrew
Created March 24, 2017 19:52
Show Gist options
  • Save brizandrew/160b412a220971e6543b231f6cea768e to your computer and use it in GitHub Desktop.
Save brizandrew/160b412a220971e6543b231f6cea768e to your computer and use it in GitHub Desktop.
Saving An Array of Python Dictionaries to a CSV file
def saveToCSV(arrayDict):
filename = 'name.csv' #call your file something
with open(filename, 'w') as output_file:
fieldnames = [ 'key1', # fill this array with the names of your keys in your dict
'key2',
...
'keyn'
]
writer = csv.DictWriter(output_file, fieldnames=fieldnames)
writer.writeheader()
writer.writerows(arrayDict)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment