Created
March 24, 2017 19:52
-
-
Save brizandrew/160b412a220971e6543b231f6cea768e to your computer and use it in GitHub Desktop.
Saving An Array of Python Dictionaries to a CSV file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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