我正在尝试将元组列表转换为pandas数据帧,但不知道如何实现。我的地址结构如下:
addresses = [
[('the vicars inn', 'house'), ('68', 'house_number'), ('church lane', 'road'), ('arlesey', 'city'), ('beds', 'house')],
[('the old oak', 'house'), ('85', 'house_number'), ('church lane', 'road'), ('arlesey', 'city'), ('beds', 'house')],
[('adj', 'road'), ('85', 'house_number'), ('high street', 'road'), ('arlesey', 'city'), ('beds', 'house')],
[('arlesey community centre', 'house'), ('high street', 'road'), ('arlesey', 'city'), ('beds', 'house')],
[('arlesey community centre', 'house'), ('high street', 'road'), ('arlesey', 'city'), ('beds', 'house')]
]
理想情况下,我需要一个数据帧:
^{pr2}$到目前为止,我所做的只是改变一下局面,但并没有产生预期的结果:
pd.DataFrame.from_records(addresses[0]).pivot(columns=1, values=0)
有没有人对实现我理想数据帧的方法有任何指导?在
山姆
您可以将每条记录转换为字典,然后使用
DataFrame.from_records
:相关问题 更多 >
编程相关推荐