【发布时间】:2018-05-19 00:01:59
【问题描述】:
我有一个字典(result_dict)如下。
{'11333216@N05': {'person': {'can_buy_pro': 0,
'description': {'_content': ''},
'has_stats': '1',
'iconfarm': 3,
'iconserver': '2214',
'id': '11333216@N05',
'ispro': 0,
'location': {'_content': ''},
'mbox_sha1sum': {'_content': '8eb2e248cbad94e2b4a5aae75eb653c7e061a90c'},
'mobileurl': {'_content': 'https://m.flickr.com/photostream.gne?id=11327876'},
'nsid': '11333216@N05',
'path_alias': 'kishansamarasinghe',
'photos': {'count': {'_content': 442},
'firstdate': {'_content': '1193073180'},
'firstdatetaken': {'_content': '2000-01-01 00:49:17'}},
'photosurl': {'_content': 'https://www.flickr.com/photos/kishansamarasinghe/'},
'profileurl': {'_content': 'https://www.flickr.com/people/kishansamarasinghe/'},
'realname': {'_content': 'Kishan Samarasinghe'},
'timezone': {'label': 'Sri Jayawardenepura',
'offset': '+06:00',
'timezone_id': 'Asia/Colombo'},
'username': {'_content': 'Three Sixty Five Degrees'}},
'stat': 'ok'},
'117692977@N08': {'person': {'can_buy_pro': 0,
'description': {'_content': ''},
'has_stats': '0',
'iconfarm': 1,
'iconserver': '404',
'id': '117692977@N08',
'ispro': 0,
'location': {'_content': 'Almere, The Nederlands'},
'mobileurl': {'_content': 'https://m.flickr.com/photostream.gne?id=117600164'},
'nsid': '117692977@N08',
'path_alias': 'meijsvo',
'photos': {'count': {'_content': 3237},
'firstdate': {'_content': '1392469161'},
'firstdatetaken': {'_content': '2013-06-23 14:39:30'}},
'photosurl': {'_content': 'https://www.flickr.com/photos/meijsvo/'},
'profileurl': {'_content': 'https://www.flickr.com/people/meijsvo/'},
'realname': {'_content': 'Markéta Eijsvogelová'},
'timezone': {'label': 'Amsterdam, Berlin, Bern, Rome, Stockholm, Vienna',
'offset': '+01:00',
'timezone_id': 'Europe/Amsterdam'},
'username': {'_content': 'meijsvo'}},
'stat': 'ok'},
'21539776@N02': {'person': {'can_buy_pro': 0,
'description': {'_content': ''},
'has_stats': '1',
'iconfarm': 0,
'iconserver': '0',
这包含超过 150 个用户名 (e.g. 11333216@N05) 。我想为每个用户提取'mobileurl' 并创建一个包含username 和mobileurl 列的数据框。我找不到迭代每个用户并提取他的mobileurl 的方法,因为索引是不可能的。但是,我已经为其中一位用户提取了 mobileurl,如下所示。
result_dict['76617062@N08']["person"]["mobileurl"]['_content']
'https://m.flickr.com/photostream.gne?id=76524249'
如果有人可以提供帮助将不胜感激,因为我对 python 有点陌生。
【问题讨论】:
-
"for user in result_dict.keys()" 将遍历所有用户
-
您确实应该发布有效的 json,我们可以直接将其加载到设施中。即你的情况下的熊猫。
标签: python json pandas dictionary flickr