如何将数据框列表转换为 python-pandas 中的面板?

How to convert a list of data frames to a panel in python-pandas?

给定具有以下格式的数据帧列表:

id  age  weight  score  date 
01  11   50      90     2011-01-23
01  12   52      89     2012-03-23
...

请注意数据框中的 id 是相同的。我希望得到一个面板,整合列表中的所有数据框,并将 ['age', 'weight', 'score'] 列作为 item-axisdate 作为 major-axis,[=13] =] 为 minor-axis。你知道怎么做吗?

提前致谢!

第一步是 concat 将您的相框放在一起:

 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])))

documentation.

中详细说明了这一点