[英]Pandas DataFrame from a dict of ndarray
Consider a dictionary like the following:考虑如下字典:
>>> dict_temp = {'a': np.array([[0,1,2], [3,4,5]]),
'b': np.array([[3,4,5], [2,5,1], [5,3,7]])}
How can I build a pandas DataFrame out of this, using a multi-index with level 0 and 1 as follows:我怎样才能建立一个 pandas DataFrame 出这个,使用具有0级和1级的多索引如下:
level_0 = ['a', 'b']
level_1 = [[0,1], [0,1,2]]
I expect the code to build the multi-index levels itself... I don't care about the column names for now.我希望代码自己构建多索引级别......我现在不关心列名。
Appreciate comments...欣赏评论...
Try concat
:尝试
concat
:
pd.concat({k:pd.DataFrame(d) for k, d in dict_temp.items()})
Output: Output:
0 1 2
a 0 0 1 2
1 3 4 5
b 0 3 4 5
1 2 5 1
2 5 3 7
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.