import pandas as pd
import xlsxwriter as xw
list1=[]
list2=[]
file_path="C:\\Users\\JPQ\\Desktop\\数据处理\\2019-1上半年.xlsx"
data=pd.read_excel(file_path)
for n in range(len(data)):
if data.at[n,"location"]==0:
list1.append(n)
df1=data.loc[:,["PNAME","CHINNAME","SVALUE"]]
# print(df1)
dict={}
workbook = xw.Workbook("fileName") # 创建工作簿
worksheet1 = workbook.add_worksheet("sheet1") # 创建子表
worksheet1.activate() # 激活表
title = ["类酵母菌","颜色","浊度","[尿液分析+]","尿糖","尿胆红素","尿酮体","尿比重","尿隐血","尿酸碱度","尿蛋白","尿胆原","尿亚硝酸盐","白细胞酯酶","红细胞","白细胞","上皮细胞","小圆上皮细胞","管型","病理管型","红细胞(高倍视野)","白细胞(高倍视野)","细菌","上皮细胞(高倍视野)","管型(低倍视野)","细菌(高倍视野)"] # 设置表头
worksheet1.write_row('B1', title)
for i in range(6042,9012):
a=list1
b=list1[i+1]-1
data2=df1[a:b]
dict=data2[["CHINNAME", "SVALUE"]].set_index("CHINNAME").to_dict()["SVALUE"]
list3=list(dict.keys())
print(list3)
print(type(list3))
# print(len(list3))
for n in list3:
if n not in title:
dict[n]="无数据"
insertData = [dict["类酵母菌"], dict["颜色"], dict["浊度"], dict["[尿液分析+]"] , dict["尿糖"],dict["尿胆红素"],dict["尿酮体"],dict["尿比重"],dict["尿隐血"],dict["尿酸碱度"],dict["尿蛋白"],dict["尿胆原"],dict["尿亚硝酸盐"],dict["白细胞酯酶"],dict["红细胞"],dict["白细胞"],dict["上皮细胞"],dict["小圆上皮细胞"],dict["管型"],dict["病理管型"],dict["红细胞(高倍视野)"],dict["白细胞(高倍视野)"],dict["细菌"],dict["上皮细胞(高倍视野)"],dict["管型(低倍视野)"],dict["细菌(高倍视野)"]]
dict.clear()
list3.clear()
row="B"+str(i+1)
worksheet1.write_row(row, insertData)
workbook.close()