pandas 生成excel
生成excel
import collections import pandas as pd def birth_to_excel(data_list,title_list, file_path): """ data_list = [ {"a": 1, "b": 2, "c": 3}, {"a": 1, "b": 2, "c": 3}, {"a": 1, "b": 2, "c": 3}, ] :param data_list: 数据 :param title_list: 标题 :param file_path: 路径 :return: """ d = collections.OrderedDict() for row in data_list: print json.dumps(row, ensure_ascii=False) for k in title_list: if k not in d: d[k] = [] d[k].append(row.get(k)) df_error = pd.DataFrame(d) convert_int_cols_to_str(df_error) df_error.to_excel(file_path, index=False, engine='openpyxl')
birth_to_excel(error_list,[u"姓名",u"身份证号",u"手机号",u"性别",u"民族",u"户籍地址",u"现住址",u"岗位",u"管理角色",u"未导入原因"], to_file_path)