[英]Converting dictionary of array to single pandas data frame
我有这本词典(pred)。 该字典包含 numpy arrays。
pred.keys()
dict_keys([0, 1]) #keys of the dictionary
pred.values() #### values of the array nested in dictionary
dict_values([array([[0.],
[0.],
[0.],
...,
[0.],
[0.],
[0.]], dtype=float32), array([[0.],
[0.],
[0.],
...,
[0.],
[0.],
[0.]], dtype=float32)])
I want to convert it into a data frame with each column showing the values of array for the dictionary key
将concat
与 DataFrame 构造函数一起使用:
pd.concat({k: pd.DataFrame(v) for k, v in pred.items()}, axis=1)
如果只需要 DataFrame 的第一列:
pd.concat({k: pd.DataFrame(v)[0] for k, v in pred.items()}, axis=1)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.