a = ['{"type": "book",',
'"title": "sometitle",',
'"author": [{"name": "somename"}],',
'"year": "2000",',
'"identifier": [{"type": "ISBN", "id": "1234567890"}],',
'"publisher": "somepublisher"}', '',
'{"type": "book",', '
'"title": "sometitle2",',
'"author": [{"name": "somename2"}],',
'"year": "2001",',
'"identifier": [{"type": "ISBN", "id": "1234567890"}],',
'"publisher": "somepublisher"}', '']
我有这个复杂的SList,我希望最终将它放入一个整洁的数据框架中
我尝试了很多方法,例如:
i = iter(a)
b = dict(zip(i, i))
不幸的是,这创建了一个看起来更糟的字典:
{'{"type": "book",':
...
在我有一份词典的地方,我现在有一本词典
我也试过了
pd.json_normalize(a)
但这会抛出一条错误消息AttributeError: 'str' object has no attribute 'values'
我也试过了
r = json.dumps(a.l)
loaded_r = json.loads(r)
print(loaded_r)
但这会产生一个列表
['{"type": "book",',
...
最后,我希望有一个像这样的熊猫数据帧
type title author year ...
book sometitle somename 2000 ...
book sometitle2 somename2 2001
显然,我还没有真正达到可以将数据提供给函数的程度。每次我这么做的时候,函数都会向我尖叫
相关问题 更多 >
编程相关推荐