diff --git a/Lec 26 - JSON with Python.ipynb b/Lec 26 - JSON with Python.ipynb index db7dd5a..034830d 100644 --- a/Lec 26 - JSON with Python.ipynb +++ b/Lec 26 - JSON with Python.ipynb @@ -1,185 +1,369 @@ -{ - "metadata": { - "name": "", - "signature": "sha256:6d2393f4566d57db7cfe7c666bb925c7e798d6bdea3c6ac40223d0d0c327a3b8" - }, - "nbformat": 3, - "nbformat_minor": 0, - "worksheets": [ - { - "cells": [ - { - "cell_type": "code", - "collapsed": false, - "input": [ - "import numpy as np\n", - "from pandas import Series, DataFrame\n", - "import pandas as pd" - ], - "language": "python", - "metadata": {}, - "outputs": [], - "prompt_number": 1 - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "# Heres an example of what a JSON (JavaScript Object Notation) looks like:\n", - "json_obj = \"\"\"\n", - "{ \"zoo_animal\": \"Lion\",\n", - " \"food\": [\"Meat\", \"Veggies\", \"Honey\"],\n", - " \"fur\": \"Golden\",\n", - " \"clothes\": null, \n", - " \"diet\": [{\"zoo_animal\": \"Gazelle\", \"food\":\"grass\", \"fur\": \"Brown\"}]\n", - "}\n", - "\"\"\"" - ], - "language": "python", - "metadata": {}, - "outputs": [], - "prompt_number": 3 - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "#Let import json module\n", - "import json\n", - "\n", - "#Lets load json data\n", - "data = json.loads(json_obj)" - ], - "language": "python", - "metadata": {}, - "outputs": [], - "prompt_number": 4 - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "#Show\n", - "data" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "metadata": {}, - "output_type": "pyout", - "prompt_number": 5, - "text": [ - "{u'clothes': None,\n", - " u'diet': [{u'food': u'grass', u'fur': u'Brown', u'zoo_animal': u'Gazelle'}],\n", - " u'food': [u'Meat', u'Veggies', u'Honey'],\n", - " u'fur': u'Golden',\n", - " u'zoo_animal': u'Lion'}" - ] - } - ], - "prompt_number": 5 - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "#WE can also convert back to JSON\n", - "json.dumps(data)" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "metadata": {}, - "output_type": "pyout", - "prompt_number": 6, - "text": [ - "'{\"food\": [\"Meat\", \"Veggies\", \"Honey\"], \"zoo_animal\": \"Lion\", \"fur\": \"Golden\", \"diet\": [{\"food\": \"grass\", \"zoo_animal\": \"Gazelle\", \"fur\": \"Brown\"}], \"clothes\": null}'" - ] - } - ], - "prompt_number": 6 - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "#We can simply open JSON data after loading with a DataFrame\n", - "dframe = DataFrame(data['diet'])" - ], - "language": "python", - "metadata": {}, - "outputs": [], - "prompt_number": 7 - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "#Show\n", - "dframe" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "html": [ - "
\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
foodfurzoo_animal
0 grass Brown Gazelle
\n", - "
" - ], - "metadata": {}, - "output_type": "pyout", - "prompt_number": 8, - "text": [ - " food fur zoo_animal\n", - "0 grass Brown Gazelle" - ] - } - ], - "prompt_number": 8 - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "# Theres lost of custom selection you can do, based on what you do or dont want in your DataFrame (you can specify columns..etc)\n" - ], - "language": "python", - "metadata": {}, - "outputs": [], - "prompt_number": 9 - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "#Next up, XML and HTML file format with python!" - ], - "language": "python", - "metadata": {}, - "outputs": [] - } - ], - "metadata": {} - } - ] -} \ No newline at end of file +{ + + "metadata": { + + "name": "", + + "signature": "sha256:6d2393f4566d57db7cfe7c666bb925c7e798d6bdea3c6ac40223d0d0c327a3b8" + + }, + + "nbformat": 3, + + "nbformat_minor": 0, + + "worksheets": [ + + { + + "cells": [ + + { + + "cell_type": "code", + + "collapsed": false, + + "input": [ + + "import numpy as np\n", + + "from pandas import Series, DataFrame\n", + + "import pandas as pd" + + ], + + "language": "python", + + "metadata": {}, + + "outputs": [], + + "prompt_number": 1 + + }, + + { + + "cell_type": "code", + + "collapsed": false, + + "input": [ + + "# Heres an example of what a JSON (JavaScript Object Notation) looks like:\n", + + "json_obj = \"\"\"\n", + + "{ \"zoo_animal\": \"Lion\",\n", + + " \"food\": [\"Meat\", \"Veggies\", \"Honey\"],\n", + + " \"fur\": \"Golden\",\n", + + " \"clothes\": null, \n", + + " \"diet\": [{\"zoo_animal\": \"Gazelle\", \"food\":\"grass\", \"fur\": \"Brown\"}]\n", + + "}\n", + + "\"\"\"" + + ], + + "language": "python", + + "metadata": {}, + + "outputs": [], + + "prompt_number": 3 + + }, + + { + + "cell_type": "code", + + "collapsed": false, + + "input": [ + + "#Let import json module\n", + + "import json\n", + + "\n", + + "#Lets load json data\n", + + "data = json.loads(json_obj)" + + ], + + "language": "python", + + "metadata": {}, + + "outputs": [], + + "prompt_number": 4 + + }, + + { + + "cell_type": "code", + + "collapsed": false, + + "input": [ + + "#Show\n", + + "data" + + ], + + "language": "python", + + "metadata": {}, + + "outputs": [ + + { + + "metadata": {}, + + "output_type": "pyout", + + "prompt_number": 5, + + "text": [ + + "{u'clothes': None,\n", + + " u'diet': [{u'food': u'grass', u'fur': u'Brown', u'zoo_animal': u'Gazelle'}],\n", + + " u'food': [u'Meat', u'Veggies', u'Honey'],\n", + + " u'fur': u'Golden',\n", + + " u'zoo_animal': u'Lion'}" + + ] + + } + + ], + + "prompt_number": 5 + + }, + + { + + "cell_type": "code", + + "collapsed": false, + + "input": [ + + "#We can also convert back to JSON\n", + + "json.dumps(data)" + + ], + + "language": "python", + + "metadata": {}, + + "outputs": [ + + { + + "metadata": {}, + + "output_type": "pyout", + + "prompt_number": 6, + + "text": [ + + "'{\"food\": [\"Meat\", \"Veggies\", \"Honey\"], \"zoo_animal\": \"Lion\", \"fur\": \"Golden\", \"diet\": [{\"food\": \"grass\", \"zoo_animal\": \"Gazelle\", \"fur\": \"Brown\"}], \"clothes\": null}'" + + ] + + } + + ], + + "prompt_number": 6 + + }, + + { + + "cell_type": "code", + + "collapsed": false, + + "input": [ + + "#We can simply open JSON data after loading with a DataFrame\n", + + "dframe = DataFrame(data['diet'])" + + ], + + "language": "python", + + "metadata": {}, + + "outputs": [], + + "prompt_number": 7 + + }, + + { + + "cell_type": "code", + + "collapsed": false, + + "input": [ + + "#Show\n", + + "dframe" + + ], + + "language": "python", + + "metadata": {}, + + "outputs": [ + + { + + "html": [ + + "
\n", + + "\n", + + " \n", + + " \n", + + " \n", + + " \n", + + " \n", + + " \n", + + " \n", + + " \n", + + " \n", + + " \n", + + " \n", + + " \n", + + " \n", + + " \n", + + " \n", + + " \n", + + "
foodfurzoo_animal
0 grass Brown Gazelle
\n", + + "
" + + ], + + "metadata": {}, + + "output_type": "pyout", + + "prompt_number": 8, + + "text": [ + + " food fur zoo_animal\n", + + "0 grass Brown Gazelle" + + ] + + } + + ], + + "prompt_number": 8 + + }, + + { + + "cell_type": "code", + + "collapsed": false, + + "input": [ + + "#You can do custom selections based on what you want in your DataFrame e.g. specify columns." + + ], + + "language": "python", + + "metadata": {}, + + "outputs": [], + + "prompt_number": 9 + + }, + + { + + "cell_type": "code", + + "collapsed": false, + + "input": [ + + "#Next up, XML and HTML file format with python!" + + ], + + "language": "python", + + "metadata": {}, + + "outputs": [] + + } + + ], + + "metadata": {} + + } + + ] + +}