Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import json
- import glob, os
- csv_content="state,timestamp,votes,eevp,trumpd,bidenj\r\n"
- #read json files
- for file in glob.glob("*.json"):
- with open(file, encoding="utf8") as f:
- x = json.load(f)
- xts = x["data"]["races"][0]["timeseries"]
- for i in range(len(xts)):
- csv_content=csv_content+f'{file[:-5]},{xts[i]["timestamp"]},{xts[i]["votes"]},{xts[i]["eevp"]},{xts[i]["vote_shares"]["trumpd"]},{xts[i]["vote_shares"]["bidenj"]}\r\n'
- #write csv table
- with open('result.csv', 'w', newline='') as f:
- f.write(csv_content)
Add Comment
Please, Sign In to add comment