如何将数据框列表转换为python-pandas中的面板? [英] How to convert a list of data frames to a panel in python-pandas?
本文介绍了如何将数据框列表转换为python-pandas中的面板?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
给出以下格式的数据框列表:
Given a list of data frames with the following format:
id age weight score date
01 11 50 90 2011-01-23
01 12 52 89 2012-03-23
...
请注意,数据框中的 id
是相同的。我希望得到一个面板,整合列表中的所有数据框,并将列 ['age','weight','score']
作为 item-axis
和 date
as major-axis
code> id as minor-axis
。你知道怎么做吗?
Please note that the id
in a data frame is same. And I wish to get a panel, integrating all the data frames in the list, and with the columns ['age', 'weight', 'score']
as item-axis
, and date
as major-axis
, and id
as minor-axis
. Do you know how to do that?
提前谢谢!
推荐答案
第一步是将 concat
>
First step is to concat
your frames together:
concated = pd.concat(list_of_frames)
然后,您可以简单地:
items = ['age', 'weight', 'score']
pd.Panel(dict(zip(items, [concated.pivot(index='date', columns='id', values=i) for i in items])))
这个在这个文档。
这篇关于如何将数据框列表转换为python-pandas中的面板?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文