Created
May 26, 2017 15:07
-
-
Save abehmiel/69a999701d279e5bf18866820a2cd34c to your computer and use it in GitHub Desktop.
JSON concatenate, dump to CSV
This file contains 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
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