Skip to content

Instantly share code, notes, and snippets.

@abehmiel
Created May 26, 2017 15:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abehmiel/69a999701d279e5bf18866820a2cd34c to your computer and use it in GitHub Desktop.
Save abehmiel/69a999701d279e5bf18866820a2cd34c to your computer and use it in GitHub Desktop.
JSON concatenate, dump to CSV
import json
import csv
# open a file for writing
data = open('trumptweets.csv', 'w')
# create the csv writer object
csvwriter = csv.writer(data)
#write the header
data_files = ['2009.json', '2010.json', '2011.json',
'2012.json', '2013.json', '2014.json',
'2015.json', '2016.json', '2017.json']
count = 0
for data_file in data_files:
with open(data_file) as f:
data = json.load(f)
for tweet in data:
if count == 0:
csvwriter.writerow(tweet.keys())
csvwriter.writerow(tweet.values())
count += 1
f.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment