规范化Pandas中的JSON文件

时间:2017-01-07 05:09:23

标签: python json pandas

我想用json文件创建一个DataFrame,json文件如下所示:



{
   "data": [
      {
         "message": "\u00a1Excelente fin de semana!",
         "link": "https://www.facebook.com/pwcmexico/photos/a.163048493732314.26589.131883973515433/1236857843018035/?type=3",
         "permalink_url": "https://www.facebook.com/pwcmexico/posts/1236857843018035:0",
         "created_time": "2017-01-07T01:00:03+0000",
         "type": "photo",
         "name": "Timeline Photos",
         "id": "131883973515433_1236857843018035",
         "shares": {
            "count": 72
         },
         "reactions": {
            "data": [
               
            ],
            "summary": {
               "total_count": 135,
               "viewer_reaction": "NONE"
            }
         },
         "likes": {
            "data": [
               
            ],
            "summary": {
               "total_count": 123,
               "can_like": true,
               "has_liked": false
            }
         },
         "comments": {
            "data": [
               
            ],
            "summary": {
               "order": "ranked",
               "total_count": 0,
               "can_comment": true
            }
         }
      },
      {
         "message": "\u00a120 a\u00f1os analizando las perspectivas de los CEO!\n\nLee c\u00f3mo ha evolucionado la plantilla de la C-Suite: http://pwc.to/2hYzwAE",
         "link": "https://www.facebook.com/pwcmexico/photos/a.163048493732314.26589.131883973515433/1236618399708646/?type=3",
         "permalink_url": "https://www.facebook.com/pwcmexico/posts/1236618399708646:0",
         "created_time": "2017-01-06T21:48:25+0000",
         "type": "photo",
         "name": "Timeline Photos",
         "id": "131883973515433_1236618399708646",
         "shares": {
            "count": 4
         },
         "reactions": {
            "data": [
               
            ],
            "summary": {
               "total_count": 5,
               "viewer_reaction": "NONE"
            }
         },
         "likes": {
            "data": [
               
            ],
            "summary": {
               "total_count": 5,
               "can_like": true,
               "has_liked": false
            }
         },
         "comments": {
            "data": [
               
            ],
            "summary": {
               "order": "ranked",
               "total_count": 0,
               "can_comment": true
            }
         }
      },
      {
         "message": "\u00bfC\u00f3mo la disrupci\u00f3n afecta la estrategia de negocio y qu\u00e9 acciones se deben tomar?\n\n#DeNovo es una plataforma para ayudar a identificar y entender esto. Conoce m\u00e1s al respecto en:",
         "link": "http://pwc.to/2hYsts0",
         "permalink_url": "https://www.facebook.com/pwcmexico/posts/1236419643061855",
         "created_time": "2017-01-06T19:27:17+0000",
         "type": "link",
         "name": "DeNovo Q3 FinTech ReView - Banks head for the cloud for reasons other than expected",
         "id": "131883973515433_1236419643061855",
         "reactions": {
            "data": [
               
            ],
            "summary": {
               "total_count": 1,
               "viewer_reaction": "NONE"
            }
         },
         "likes": {
            "data": [
               
            ],
            "summary": {
               "total_count": 1,
               "can_like": true,
               "has_liked": false
            }
         },
         "comments": {
            "data": [
               
            ],
            "summary": {
               "order": "ranked",
               "total_count": 0,
               "can_comment": true
            }
         }
      }
],
   "paging": {
  "previous": "https://graph.facebook.com/v2.6/131883973515433/posts?fields=message,link,permalink_url,created_time,type,name,id,comments.limit\u0025280\u002529.summary\u002528true\u002529,shares,likes.limit\u0025280\u002529.summary\u002528true\u002529,reactions.limit\u0025280\u002529.summary\u002528true\u002529&limit=100&since=1483750803&access_token=EAACEdEose0cBAJJcJ55AYSjSugrByMsZBVWLICJqQY3rT1paASP4PzEKhSMl2P4gVGlPpjbgezZBWjZCLbtTH1KaVr7PFfZBqaYgXiQXcScDUSkYf5abFn7ZBiv96ICNxkkDChvvWY3edGNYciLZApr7GgS65yRbbBqMrae5josgZDZD&__paging_token=enc_AdDbvdPWoEkhs6FAU4bLG849iCWfhDkRZCBrLokYjFVB3p55bMgN83rYTED1pPXP92cExZBSKU1KCVkfBB5PSRUZCUk7YGMY34eZAHolmO5ZCGZA4RigZDZD&__previous=1",
  "next": "https://graph.facebook.com/v2.6/131883973515433/posts?fields=message,link,permalink_url,created_time,type,name,id,comments.limit\u0025280\u002529.summary\u002528true\u002529,shares,likes.limit\u0025280\u002529.summary\u002528true\u002529,reactions.limit\u0025280\u002529.summary\u002528true\u002529&limit=100&access_token=EAACEdEose0cBAJJcJ55AYSjSugrByMsZBVWLICJqQY3rT1paASP4PzEKhSMl2P4gVGlPpjbgezZBWjZCLbtTH1KaVr7PFfZBqaYgXiQXcScDUSkYf5abFn7ZBiv96ICNxkkDChvvWY3edGNYciLZApr7GgS65yRbbBqMrae5josgZDZD&until=1480360200&__paging_token=enc_AdAGurbTaBdlNdNKylAoJKNJAPNjsRgSF3aym8iVUXhEOIgGOUxYu8T5diEai2I3YvKlV69zZCK62AYLzyxpxQzozuKV516ZA96cv4kWbixYeAeAZDZD"
   }
}




而且我不知道如何开始,有一个实际上有它的在线页面,但是我想自己学习和做,这是网站:https://konklone.io/json/

我正在使用pandas.io.json.json_normalize,但我没有结果,任何想法如何处理这个。

我试过这个:



db = pd.io.json.json_normalize(body, 'data',['message', 'link', 'permalink_url','created_time','type','name','id',['shares','count'],['reactions','summary','total_count'],['reactions','summary','viewer_reaction'],['likes','summary','total_count'],['likes','summary','has_liked'],['comments','summary','order'],['comments','summary','total_count'],['comments','summary','can_comment']])




由于

0 个答案:

没有答案