我有以下表格中的一些数据:
a = [{'table': 'a', 'field':['apple', 'pear']},
{'table': 'b', 'field':['grape', 'berry']}]
我想创建一个如下所示的数据帧:
^{pr2}$当我尝试这个:
pd.DataFrame.from_records(a)
我明白了:
field table
0 [apple, pear] a
1 [grape, berry] b
我正在使用一个循环来重新构造我的原始数据,但是我认为必须有一个更直接、更简单的methid。在
选项1
理解力
选项2
^{pr2}$重建
选项3
魔方
您可以使用列表理解来连接一系列数据帧,
a
中的每个字典对应一个。在或者你可以尝试使用
pd.wide_to_long
,我确实想用lreshape
,但这是没有文档记录的,个人不建议使用pd.wide_to_long
^{pr2}$
相关问题 更多 >
编程相关推荐