如何将嵌套列表转换为数据框
我有一个嵌套的列表看起来很重要:
[[{'aaa': '42'}, {'bbb': '60'}, {'ccc': '25'}, {'ddd': '14'}, {'eee': '15'}, {'eee': '84'}],
[{'aaa': '4'}, {'bbb': '0'}, {'ccc': '25'}, {'ddd': '1'}, {'eee': '1'}, {'eee': '8'}]]
我想将其转换为数据框架。 我在门户网站上查看了许多解决方案,但对我没有任何帮助:( 请帮助我,因为我在Python和Pandas模块中更新鲜。谢谢你!
这是我所需的输出:
我正在做这样的事情,但它对我不起作用: dataframe(data_dicts)
I have a nested list looked liek this:
[[{'aaa': '42'}, {'bbb': '60'}, {'ccc': '25'}, {'ddd': '14'}, {'eee': '15'}, {'eee': '84'}],
[{'aaa': '4'}, {'bbb': '0'}, {'ccc': '25'}, {'ddd': '1'}, {'eee': '1'}, {'eee': '8'}]]
And I want to convert it into a Dataframe.
I looked at many solutions on our portal but nothing works for me :(
Please help me as I'm a fresher in Python and Pandas module. Thank you!
Here is my desired Output:
I'm doing something like this but it's not working for me:
DataFrame(data_dicts)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
假设
l
您的输入列表,您可以使用列表/字典理解:nb。请注意,您的字典中有重复的键, last 一个优先级
输出:
输入:
Assuming
L
your input list, you can use a list/dictionary comprehension:NB. note that you have duplicated keys in your dictionaries, the last ones take precedence
output:
input:
您可以使用
collections.defaultDict
一起收集键的所有值,然后使用pd.concat
来构造数据框 -output
You can use a
collections.defaultdict
to collect all values of a key together and then usepd.concat
to construct a dataframe -Output