def write_to_csv(file, all_data):
senators = set()
for bill in all_data:
for vote in bill['votes']:
senators.add(vote['senator'])
headers = ['description', 'date']
headers.extend(senators)
with open(file, 'w') as csvfile:
writer = csv.DictWriter(csvfile, fieldnames=headers, restval='N/A')
writer.writeheader()
for bill in all_data:
row = {
'description': bill['description'],
'date': bill['date'].replace(',', '/')
}
row.update({b['senator']: b['voted'] for b in bill['votes']})
writer.writerow(row)
# Save data to JSON
评论列表
文章目录