我想通过在出现的每个引号之后将它们拆分来将键中的值分组到值列表中。因此,每个地标都被分配了一个位置列表,例如:
{'Landmarks': ['Great norwich', 'Larger building', 'Leaning building'],
'location': ['North 28th Street',
'Stadium High School',
'',
'Charles Bridge',
"St Vitus' Cathedral",
'',
'All Saints Church',
'Royal Courts of Justice',
'Lonsdale Road']
}
预期输出:
作为字典:
{'Landmarks': ['Great norwich', 'Larger building', 'Leaning building'],
'location': [['North 28th Street', 'Stadium High School'],
['Charles Bridge', "St Vitus' Cathedral"],
['All Saints Church', 'Royal Courts of Justice', 'Lonsdale Road']]
}
或作为数据框:
Landmarks Locations
Great norwich ['North 28th Street','Stadium High School']
Larger building ['Charles Bridge','St Vitus' Cathedral',]
Leaning building ['All Saints Church','Royal Courts of Justice','Lonsdale Road']
我试过了:
pd.DataFrame(data)
我得到错误->
数组的长度必须相同
我可以删除引号:
for v in data.values():
if ('') in v:
v.remove((''))
尽管如何在删除之前将引号之前的所有值分配为列表,以获得上面的预期值?