2017-12-06 9 views
0
{ 
"total_count": 2316913, 
"incomplete_results": false, 
"items": [ 
    { 
     "id": 13737149, 
     "name": "gremlins.js", 
     "full_name": "marmelab/gremlins.js", 
     "owner": { 
      "login": "marmelab", 
      "id": 3116319, 
      "avatar_url": "https://avatars1.githubusercontent.com/u/3116319?v=4", 
      "gravatar_id": "", 
      "url": "https://api.github.com/users/marmelab", 
      "html_url": "https://github.com/marmelab", 
      "followers_url": "https://api.github.com/users/marmelab/followers", 
      "following_url": "https://api.github.com/users/marmelab/following{/other_user}", 
      "gists_url": "https://api.github.com/users/marmelab/gists{/gist_id}", 
      "starred_url": "https://api.github.com/users/marmelab/starred{/owner}{/repo}", 
      "subscriptions_url": "https://api.github.com/users/marmelab/subscriptions", 
      "organizations_url": "https://api.github.com/users/marmelab/orgs", 
      "repos_url": "https://api.github.com/users/marmelab/repos", 
      "events_url": "https://api.github.com/users/marmelab/events{/privacy}", 
      "received_events_url": "https://api.github.com/users/marmelab/received_events", 
      "type": "Organization", 
      "site_admin": false 
     }, 

上記はGithub検索APIのデータです。私がしようとしているのは、特定のフィールドを取り出してデータフレームに挿入することです。以下のようなループのための標準を使用してpython:JSONデータをデータフレームに挿入

for i in jdata['items']: 
    print(i['name'] + "\t" + i['html_url']) 

は私が必要とするデータを印刷し、しかし、その醜い、読みにくい、と私は抽出するより多くのものを持っているので、私は停止点でです。

url = "https://api.github.com/search/repositories?q={}".format(sTerm) 
jdata = requests.get(url).json() 

私はこれを使用してユーザーから入力を受け取り、その結果をjdataに格納します。

データフレームは私にとって初めてのもので、何を試しても検索結果には何も表示されません。私が間違っていることを確信していない。 (私はすべてのデータフレームのコードを貼り付けていなかった知っている、何も作業していないので、私は、私は誰もが目のがんを保存したい考え出し。)

答えて

1

それはあなたが

import pandas as pd 
df = pd.DataFrame(jdata['items'], columns=['name', 'html_url']) 

のような何かをしたいように聞こえます例は、sTerm場合、一度働いI印刷添加

In [15]: pd.DataFrame(jdata['items'], columns=['name', 'html_url']) 
Out[15]: 
       name          html_url 
0    Hest   https://github.com/MegaCakeEater/Hest 
1    heston   https://github.com/daleroberts/heston 
2 NotoSansKR-Hestia https://github.com/theeluwin/NotoSansKR-Hestia 
3    hest    https://github.com/mastensg/hest 
4    Heston    https://github.com/jcfrei/Heston 
5    Hest   https://github.com/abirk2thebone/Hest 
6    Hest     https://github.com/h6899/Hest 
7    Hest     https://github.com/hsurce/Hest 
8    hest     https://github.com/kmajo/hest 
+0

うん、'hest'ある(df.to_stringを())。ありがたいことに、私はその近くにいませんでした。 – Josh

+0

あなたは大歓迎です。その答えが役に立つと分かったら、[それを受け入れる]ことができます(https://stackoverflow.com/help/someone-answers)。 – fuglede