赞
踩
Input:
Output:
[
{“A”: “a2”, “B”: “b2”, “C”: “c2”, “D”: “d2”},
{“A”: “a3”, “B”: “b3”, “C”: “c3”, “D”: “d3”},
{“A”: “a4”, “B”: “b4”, “C”: “c4”, “D”: “d4”}
…
]
code:
import pandas as pd
ex_data = pd.read_excel("test.xlsx") #默认读取第一个sheet的内容
head_list = list(ex_data.columns) #拿到表头: [A, B, C, D]
list_dic = []
for i in ex_data.values: # i 为每一行的value的列表:[a2, b2, c2, d2]
a_line = dict(zip(head_list, i)) # a_line: {"A": "a2", "B": "b2", "C": "c2", "D": "d2"}
list_dic.append(a_line)
print(list_dic)
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。