2 回答
TA贡献1775条经验 获得超8个赞
我想这就是你想要的:
data = [{'Route Nr.': 1, 'City Nr.': 0, 'City Name': 'EMTE HEADQUARTERS VEGHEL', 'Total Distance in Route (km)': 0, 'Total Distance (km)': 0}, {'Route Nr.': 1, 'City Nr.': 78, 'City Name': 'EMTE OLDEBROEK FR', 'Total Distance in Route (km)': 97, 'Total Distance (km)': 97}]
header = ','.join(data[0].keys()) + '\n'
f = open('output.xls','w')
f.write(header)
for line in range(len(data)):
f.write(','.join(str(element) for element in data[line].values())+'\n')
f.close()
输出:
TA贡献1934条经验 获得超2个赞
可能有很多方法可以做到这一点,这是我的答案版本:
import pandas as pd
mylist = <YOUR LIST OF DICTIONARIES>
df = pd.DataFrame(mylist)
df.to_excel(r'exaple.xls', index = False)
添加回答
举报