1
我试图将元组列表转换为熊猫数据帧,但无法弄清楚如何实现。我的地址的结构如下所示:将元组列表转换为熊猫数据帧
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')]
]
理想情况下,我需要回到像一个数据帧:
city house house_number road
0 arlesey the vicars inn 68 church lane
1 arlesey the old oak 85 church lane
我已经试过到目前为止转动表,但它不产生预期结果:
pd.DataFrame.from_records(addresses[0]).pivot(columns=1, values=0)
有没有人有任何指导方法,我应该看看实现我理想的数据框?
山姆
看来你在每个记录两套房子。你想保留哪一个? – Psidom