我有一个Python字典,格式如下:
dict = {
D:""
B:""
A:""
C:""
}
然而,当我将这个字典写入Excel的csv文件时,列会被重新排列。
A B C D
当我将字典写入Excel时,如何在Python中保持其顺序?
writer = pd.ExcelWriter('list_of_detected_words.xlsx', engine='xlsxwriter')
list_of_detected_words = pd.DataFrame.from_records(form_info)
list_of_detected_words.to_excel(writer, "Sheet1",startrow=1)
上面是写入Excel的代码。