无法在这个位置找到: head2.htm
当前位置: 建站首页 > 新闻动态 > 行业新闻 >

Python读写能力CSV文档

时间:2021-04-06 20:46来源:未知 作者:jianzhan 点击:
"Jules,Dicki,Lake Nickolasville".split(","),"Dedric,Medhurst,Stiedemannberg".split(",")]path="out.csv"csv_writer(data,path)# 方法二:应用csv控制模块的DictReaderdef csv_dict_writer(path,fieldnames,data):with open(path,"w",newline=
"Jules,Dicki,Lake Nickolasville".split(","), "Dedric,Medhurst,Stiedemannberg".split(",")] path="out.csv" csv_writer(data,path) # 方法二:应用csv控制模块的DictReader def csv_dict_writer(path,fieldnames,data): with open(path,"w",newline="") as out_file: writer=csv.DictWriter(out_file,delimiter=',',fieldnames=fieldnames) writer.writeheader() for row in data: writer.writerow(row) if __name__ == '__main__': data=["first_name,last_name,city".split(","), "Tyrese,Hirthe,Strackeport".split(","), "Jules,Dicki,Lake Nickolasville".split(","), "Dedric,Medhurst,Stiedemannberg".split(",")] path="dict_output.csv" my_list=[] fieldnames=data[0] for values in data[1:]: inner_dict=dict(zip(fieldnames,values)) # 组装成字典 my_list.append(inner_dict) csv_dict_writer(path,fieldnames,my_list)

注:TB_data_dictionary_2020-07-17.csv 文档文件格式以下:

"variable_name","dataset","code_list","definition"
"budget_cpp_dstb","Budget",,"Average cost of drugs budgeted per patient for drug-susceptible TB treatment, excluding buffer stock (US Dollars)"
"budget_cpp_mdr","Budget",,"Average cost of drugs budgeted per patient for MDR-TB treatment, excluding buffer stock (US Dollars)"
(责任编辑:admin)
织梦二维码生成器
顶一下
(0)
0%
踩一下
(0)
0%
------分隔线----------------------------
无法在这个位置找到: ajaxfeedback.htm
栏目列表
推荐内容


扫描二维码分享到微信