def DailyTotal(InputData, DateCol, ColRename, ColSumName): date = _utils.convertDatetime(InputData, DateCol) temp = date.value_counts() temp = temp.to_frame() OutputData = _utils.imputateDate(temp).replace(np.nan, 0).copy() OutputData[ColSumName] = OutputData[DateCol].cumsum() return (OutputData)
def dateTabling(df_, col): table = df_.groupby(by=col)["count"].sum().to_frame() #print(df_[col].values) #print(table) table = _utils.imputateDate(table) table["累積"] = table["count"].cumsum() return(table)
def tableProcessing(df1, path): # datetime conversion for c in colList: try: df1[c] = df1[c].dt.date except: pass # get death date deathCol = "死亡日" status = "転帰" cond = df1[status] == "02_死亡" df1[deathCol] = np.nan df1.loc[cond, deathCol] = df1.loc[cond, outCol] # tabling df1['count'] = 1 posi = df1[posCol].value_counts() posi = posi.to_frame() table = tablingMerge(posi, df1, onsetCol) table = tablingMerge(table, df1, inHospCol) table = tablingMerge(table, df1, negSt) table = tablingMerge(table, df1, negConf) table = tablingMerge(table, df1, outCol) table = tablingMerge(table, df1, deathCol) table = _utils.imputateDate(table) table = table.replace(np.nan, 0) table['累積陽性者数'] = table['陽性確定日'].cumsum() table['累積陰性者数'] = table['陰性結果確認日'].cumsum() table['累積死亡者数'] = table['死亡日'].cumsum() table['累積退院者数'] = table['退院日'].cumsum() table['累積入院者数'] = table['入院日'].cumsum() table['累積発症者数'] = table['発症日'].cumsum() table = table.rename( columns={ '陽性確定日': '陽性者数', '発症日': '発症者数', '入院日': '入院者数', '陰性結果開始日': '陰性検査開始数', '陰性結果確認日': '陰性者数', '退院日': '退院者数', '死亡日': '死亡者数', }) table['現在患者数'] = table['累積入院者数'] - table['累積退院者数'] dir_ = _utils.getOutputDir() pathOutput = dir_ + path.split("/")[-1][:-5] + "_table7.xlsx" with pd.ExcelWriter(pathOutput, engine='openpyxl', mode='w') as writer: table.to_excel(writer, sheet_name="日付別集計"),
def DailyTotal2(InputData, DateCol, ColumnName): df_ = InputData[[DateCol, ColumnName]].copy() df_[DateCol] = df_[DateCol].dt.date df_['count'] = 1 temp = pd.pivot_table(df_, values=['count'], index=[DateCol], columns=[ColumnName], aggfunc=np.sum, fill_value=0) OutputData = _utils.imputateDate(temp).copy() return (OutputData)
def regDateAgeCrossTab(dfM,path2Save2,path,phcVals,ageVals,col1,col2): with pd.ExcelWriter(path2Save2, engine="openpyxl", mode="wa") as writer: # dfError = _utils.createErrorCheckDF(path) # dfError.to_excel(writer, sheet_name="エラー確認") for hC in phcVals: cond2 = dfM[phcCol] == hC dfM2 = dfM[cond2] #print(hC) if dfM2.shape[0] == 0: continue regDateDF = dfM2.pivot_table(index = col1,columns = col2,values="count",aggfunc=np.sum) regDateDF = regDateDF.replace(np.nan,0) if regDateDF.shape[0] == 0: continue regDateDF = _utils.imputateDate(regDateDF) for c in ageVals: if c not in regDateDF.columns: regDateDF[c] = 0 #print(sortCol) #display(regDateDF) # save data regDateDF.to_excel(writer,sheet_name=hC,columns=ageVals)
def regDateCrossTab(dfM,col1,col2): regDateDF = dfM.pivot_table(index = col1,columns = col2,values="count",aggfunc=np.sum) regDateDF = regDateDF.replace(np.nan,0) regDateDF = _utils.imputateDate(regDateDF) return(regDateDF)