将带有DICT的元素转换为Pandas DataFrame
我有一个列表,其中包含dict的元素,我想将其解析到Pandas DataFrame。
[
(
{'resource': 'Observation1', 'date': '2021-06-01 11:39:00', 'code': '15848'},
{'date': '2021-04-14 00:00:00','resource': 'Observation2'}
),
(
{'resource': 'Observation1', 'date': '2011-04-01 11:39:00', 'code': '15848'},
{'date': '2012-06-15 00:00:00','resource': 'Observation2'}
),
]
结果框架看起来如下:
x_resource x_date x_code y_date y_resource
Observation 1 2021-06-01 11:39:00 15848 2021-04-14 00:00:00 Observation 2
Observation 1 2011-04-01 11:39:00 15848 2012-06-15 00:00:00 Observation 2
我尝试使用pd.multiindex.from_tuples,但无法处理元组中的dicts ...
关于如何解决此问题的任何建议? 感谢您的帮助!
I have a list with tuples that contain dicts which I would like to parse to a pandas dataframe.
[
(
{'resource': 'Observation1', 'date': '2021-06-01 11:39:00', 'code': '15848'},
{'date': '2021-04-14 00:00:00','resource': 'Observation2'}
),
(
{'resource': 'Observation1', 'date': '2011-04-01 11:39:00', 'code': '15848'},
{'date': '2012-06-15 00:00:00','resource': 'Observation2'}
),
]
The resulting dataframe would look as follows:
x_resource x_date x_code y_date y_resource
Observation 1 2021-06-01 11:39:00 15848 2021-04-14 00:00:00 Observation 2
Observation 1 2011-04-01 11:39:00 15848 2012-06-15 00:00:00 Observation 2
I have tried to use the pd.MultiIndex.from_tuples but it can't handle the dicts within the tuples...
Any suggestion on how to solve this?
Thank you for your help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对我来说,这个代码工作正常。我认为解决问题对您有帮助。
For me this code is working fine. I think it would be helpful for you to solve the problem.