Last active
December 17, 2015 23:59
-
-
Save apremalal/5693240 to your computer and use it in GitHub Desktop.
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
| import unicodecsv,json | |
| import sys | |
| def convert2csv(data): | |
| fieldnames = ['user_id','name','average_stars','review_count','type'] #Filed names to filter and record, json stream | |
| with open('test.csv', 'wb+') as f: | |
| dict_writer = unicodecsv.DictWriter(f, fieldnames=fieldnames) | |
| dict_writer.writerow(dict(zip(fieldnames, fieldnames))) | |
| for line in data: | |
| row = json.loads(line) | |
| dict_writer.writerow(row) | |
| if __name__ == '__main__': | |
| inputdata = open(sys.argv[1]) | |
| convert2csv(inputdata) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment