我有这种形式的一些数据:熊猫数据帧从列表/字典/列表
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
我正在使用一个循环来重构我的原始数据,但我认为必须有一个更直接和更简单的方法。
你如何推断'浆果C'?不应该是'b'。 – umutto
@umutto是正确的 - 我将编辑问题 –