python list of dictionaries to excel

Solutions on MaxInterview for python list of dictionaries to excel by the best coders in the world

showing results for - "python list of dictionaries to excel"
Marta
06 Apr 2016
1from csv import DictWriter
2
3players = [{'dailyWinners': 3, 'dailyFreePlayed': 2, 'user': 'Player1', 'bank': 0.06},
4{'dailyWinners': 3, 'dailyFreePlayed': 2, 'user': 'Player2', 'bank': 4.0},
5{'dailyWinners': 1, 'dailyFree': 2, 'user': 'Player3', 'bank': 3.1},            
6{'dailyWinners': 3, 'dailyFree': 2, 'user': 'Player4', 'bank': 0.32}]
7
8with open('spreadsheet.csv','w') as outfile:
9    writer = DictWriter(outfile, ('dailyWinners','dailyFreePlayed','dailyFree','user','bank'))
10    writer.writeheader()
11    writer.writerows(players)