我有一本這種格式的字典:dict = { (A1,col1):3, (A1,col2):[1,2,3] ... (B1,col1):2,(B1,col2):[2,3]}是否可以構造一個具有多級索引的數據框 A1 ... B1 col1 col2 col1 col20 3 [1,2,3] 2 [2,3]我嘗試使用構建數據框,pd.DataFrame(v)但得到了Value Error all arrays must be the same length.
1 回答

慕村9548890
TA貢獻1884條經驗 獲得超4個贊
嘗試這個:
pd.DataFrame(dd.values(), index=pd.MultiIndex.from_tuples(list(dd.keys()))).T
輸出:
A1 B1
col1 col2 col1 col2
0 3 [1, 2, 3] 2 [2, 3]
添加回答
舉報
0/150
提交
取消