我創建了一個數據框,如圖所示:idx = pd.MultiIndex.from_product([['batch1', 'batch2','batch3', 'batch4', 'batch5'], ['quiz1', 'quiz2']])cols=['noofpresent', 'lesserthan50', 'between50and60', 'between60and70', 'between70and80', 'greaterthan80']statdf = pd.DataFrame('-', idx, cols)statdfstatdf.loc['quiz1', 'noofpresent'] = qdf1.b4ispresent.count()statdf.loc['quiz2', 'noofpresent'] = qdf2.b4ispresent.count()statdf.noopresent = qdf1.b4ispresent.count()statdf.noopresent = qdf2.b4ispresent.count()statdf然后我做了一些計算。我現在想分別在“ batch4 ”、“quiz1”和“quiz2”的“noofpresent”列中附加數字“50”和“53”的具體計算。但相反,這發生了......如何將數據插入正確的位置?
1 回答

Smart貓小萌
TA貢獻1911條經驗 獲得超7個贊
你可以像這樣索引它。
statdf.loc['batch4','quiz1']['noofpresent'] = qdf1.b4ispresent.count()
statdf.loc['batch4','quiz2']['noofpresent'] =qdf2.b4ispresent.count()
添加回答
舉報
0/150
提交
取消