Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/315.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
python:将JSON数据插入数据帧_Python_Json_Pandas_Dataframe - Fatal编程技术网

python:将JSON数据插入数据帧

python:将JSON数据插入数据帧,python,json,pandas,dataframe,Python,Json,Pandas,Dataframe,以上是来自Github搜索API的数据。我试图做的是拉出某些字段并将其插入到数据帧中 使用类似循环的标准: { "total_count": 2316913, "incomplete_results": false, "items": [ { "id": 13737149, "name": "gremlins.js", "full_name": "marmelab/gremlins.js", "owner": {

以上是来自Github搜索API的数据。我试图做的是拉出某些字段并将其插入到数据帧中

使用类似循环的标准:

{
"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
        },
打印出我需要的数据,但是,它很难看,很难阅读,而且因为我有更多的东西要提取,我正处于一个停止点

for i in jdata['items']:
  print(i['name']  + "\t" + i['html_url'])
我使用它从用户那里获取输入,并将结果存储在jdata中


数据帧对我来说是新事物,似乎无论我尝试什么,它要么显示搜索结果中的所有内容,要么什么都不显示。不知道我做错了什么。(我知道我没有粘贴任何数据帧代码,任何东西都不起作用,所以我想我可以让每个人都免于患上眼癌。)

听起来你想做类似的事情

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

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

是的,一旦我添加了print(df.to_string()),它就可以工作了。谢谢你,我离那不远,不客气。如果你觉得答案有帮助,你可以。
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