辞書のリストを Excel ワークシートに書き込む方法があります。まず、持っていることを確認してくださいXlsxWriter package
。
from xlsxwriter import Workbook
players = [{'dailyWinners': 3, 'dailyFree': 2, 'user': 'Player1', 'bank': 0.06},
{'dailyWinners': 3, 'dailyFree': 2, 'user': 'Player2', 'bank': 4.0},
{'dailyWinners': 1, 'dailyFree': 2, 'user': 'Player3', 'bank': 3.1},
{'dailyWinners': 3, 'dailyFree': 2, 'user': 'Player4', 'bank': 0.32}]
ordered_list=["user", "dailyWinners", "dailyFree", "bank"] # List object calls by index, but the dict object calls items randomly
wb=Workbook("New File.xlsx")
ws=wb.add_worksheet("New Sheet") # Or leave it blank. The default name is "Sheet 1"
first_row=0
for header in ordered_list:
col=ordered_list.index(header) # We are keeping order.
ws.write(first_row,col,header) # We have written first row which is the header of worksheet also.
row=1
for player in players:
for _key,_value in player.items():
col=ordered_list.index(_key)
ws.write(row,col,_value)
row+=1 #enter the next row
wb.close()
コードを試してみたところ、うまくいきました。