【发布时间】:2018-02-03 00:17:09
【问题描述】:
我有一些这种形式的数据:
a = [{'table': 'a', 'field':['apple', 'pear']},
{'table': 'b', 'field':['grape', 'berry']}]
我想创建一个如下所示的数据框:
field table
0 apple a
1 pear a
2 grape b
3 berry b
当我尝试这个时:
pd.DataFrame.from_records(a)
我明白了:
field table
0 [apple, pear] a
1 [grape, berry] b
我正在使用循环来重构我的原始数据,但我认为必须有一个更直接和更简单的方法。
【问题讨论】:
-
你如何推断
berry c?不应该是b。 -
@umutto 是正确的 - 我会编辑问题