def diagnosticEngineering(df,pullDown,path): phcVals = pullDown[phcCol].dropna().values ageVals = pullDown[ageCol].dropna().values sexVals = pullDown[sexCol].dropna().values dfM = df.copy() dfM["count"] = 1 dfM = dataCleaning(dfM) regTable = _utils.basicTable(dfM, phcCol,phcVals) ageTable = _utils.basicTable(dfM,ageCol,ageVals) sexTable = _utils.basicTable(dfM,sexCol,sexVals) dateTable = dateTabling(dfM,testDateCol) regDateTable = regDateCrossTab(dfM,col1=testDateCol,col2=phcCol) regDateCumTable = regDateTable.cumsum() dir_ = _utils.getOutputDir() path2Save1 = dir_ + path.split("/")[-1][:-5] + f"_陽性者集計1.xlsx" path2Save2 = dir_ + path.split("/")[-1][:-5] + f"_陽性者集計2.xlsx" with pd.ExcelWriter(path2Save1, engine="openpyxl", mode="wa") as writer: #dfError = _utils.createErrorCheckDF(path) #dfError.to_excel(writer, sheet_name="エラー確認") regTable.to_excel(writer ,sheet_name="保健所") ageTable.to_excel(writer, sheet_name="年齢") sexTable.to_excel(writer, sheet_name="性別") dateTable.to_excel(writer, sheet_name="日付") regDateTable.to_excel(writer, sheet_name="日付-地域") regDateCumTable.to_excel(writer, sheet_name="日付-地域-累積") regDateAgeCrossTab(dfM,path2Save2,path,phcVals,ageVals,testDateCol,ageCol)
def crossTabulation(df, path): hc_occur = _utils.basicTable(df, '保健所', '発生状況(公表)') age_hcSex = _utils.basicTable(df, '年代', ['保健所', '性別']) hosp_bedUnhosp = _utils.basicTable(df, '入院医療機関(現在)', ['入院病床(現在)', '退院の有無']) age_sexResult = _utils.basicTable(df, '年代', ['性別', '身体状況(現在の症状)']) dir_ = _utils.getOutputDir() pathOutput = dir_ + path.split("/")[-1][:-5] + f"_層別集計.xlsx" with pd.ExcelWriter(pathOutput, engine='openpyxl', mode='w') as writer: hc_occur.to_excel(writer, sheet_name="保健所×発生状況"), age_hcSex.to_excel(writer, sheet_name="年代×保健所性別"), hosp_bedUnhosp.to_excel(writer, sheet_name="入院医療機関×病床退院"), age_sexResult.to_excel(writer, sheet_name="年代×性別現在の状況"),
def getHospitalTable(df_): df_[inHosp] = df_[inHosp].dt.date cond = df_[inHosp].apply(type) == type(datetime.date(2020, 1, 1)) df_[inOrNot] = "空白" df_.loc[cond, inOrNot] = "有" tableIn = _utils.basicTable(df_, phc, inOrNot) tableIn = tableIn.add_prefix(inOrNot + "_") tableOut = _utils.basicTable(df_, phc, outOrNot) tableOut = tableOut.add_prefix(outOrNot + "_") tableHosp = pd.concat((tableIn, tableOut), axis=1) # tableHosp["現在入院患者数"] =\ # tableHosp[inOrNot +"_有"] - tableHosp[outOrNot + "_01_有"] return (tableHosp)
def getStatusTable(df_, col): table = _utils.basicTable(df_, phc, col) perLis = ["01_孤発", "02_初発", "03_後発"] for c in perLis: if c not in table.columns: table[c] = 0 tablePer = table[perLis] tablePer = tablePer.divide(tablePer.sum(axis=1), axis=0) tablePer["合計"] = tablePer.sum(axis=1) tablePer = np.round(tablePer * 100, 2) table = table.add_suffix("_(N)") tablePer = tablePer.add_suffix("_(%)") ret = pd.concat((table, tablePer), axis=1) return (ret)
def tableProcessing(df, path): df = df.dropna(axis=0, how="all") for c in [phc, statusPub, outOrNot, physicalStatus]: df[c] = df[c].replace(np.nan, '空白') df["count"] = 1 tablePub = getStatusTable(df, statusPub) tablePhysical = _utils.basicTable(df, phc, physicalStatus) tableHosp = getHospitalTable(df) dir_ = _utils.getOutputDir() pathOutput = dir_ + path.split("/")[-1][:-5] + f"_発生状況.xlsx" with pd.ExcelWriter(pathOutput, engine="openpyxl", mode="wa") as writer: tablePub.to_excel(writer, sheet_name="公表") tablePhysical.to_excel(writer, sheet_name="身体状況") tableHosp.to_excel(writer, sheet_name="入院状況")