将词典转换为熊猫数据框
我有一个字典,其中值为odict_items
:
{1: odict_items([('a', 0.0952), ('b', 14.583351), ('c', 120000), ('d', 6000)]),
2: odict_items([('a', 0.098733336), ('b', 14.526156), ('c', 120000), ('d', 6000)])}
当我将其转换为dataframe时,输出如下:
df = pd.dataframe(dict.values()
0 1 2 3
0 (a, 0.0952) (b, 14.583351) (c, 120000) (d, 6000)
1 (a, 0.0987) (b, 14.526156) (c, 120000) (c, 6000)
)所需的输出如下(第一列是密钥,下一列是ODICT_ITEMS中的值):
a b c d
1 0.0952 14.583351 120000 6000
2 0.0987 14.526156 120000 6000
任何帮助都将不胜感激。
I have a dictionary in which values are odict_items
:
{1: odict_items([('a', 0.0952), ('b', 14.583351), ('c', 120000), ('d', 6000)]),
2: odict_items([('a', 0.098733336), ('b', 14.526156), ('c', 120000), ('d', 6000)])}
When I convert it to a dataframe the output is as follows:
df = pd.DataFrame(dict.values())
0 1 2 3
0 (a, 0.0952) (b, 14.583351) (c, 120000) (d, 6000)
1 (a, 0.0987) (b, 14.526156) (c, 120000) (c, 6000)
But the desired output is as follows (first column is the key and the next columns are values in odict_items):
a b c d
1 0.0952 14.583351 120000 6000
2 0.0987 14.526156 120000 6000
Any help would be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要从项目中重建有效词典:
输出:
二手输入:
You need to reconstruct valid dictionaries from the items:
Output:
Used input: