{ "metadata": { "name": "", "signature": "sha256:1c9c0d174dc331d2feb2d83313cdd1b55ff0be3459b17d693386fc33f646bd3b" }, "nbformat": 3, "nbformat_minor": 0, "worksheets": [ { "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "**Work in Progress**" ] }, { "cell_type": "code", "collapsed": false, "input": [ "# read population in\n", "import json\n", "import requests\n", "from pandas import DataFrame\n", "\n", "# pop_json_url holds a \n", "pop_json_url = \"https://gist.github.com/rdhyee/8511607/raw/f16257434352916574473e63612fcea55a0c1b1c/population_of_countries.json\"\n", "pop_list= requests.get(pop_json_url).json()\n", "\n", "df = DataFrame(pop_list)\n", "df[:5]" ], "language": "python", "metadata": {}, "outputs": [ { "html": [ "
\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
012
0 1 China 1385566537
1 2 India 1252139596
2 3 United States 320050716
3 4 Indonesia 249865631
4 5 Brazil 200361925
\n", "

5 rows \u00d7 3 columns

\n", "
" ], "metadata": {}, "output_type": "pyout", "prompt_number": 1, "text": [ " 0 1 2\n", "0 1 China 1385566537\n", "1 2 India 1252139596\n", "2 3 United States 320050716\n", "3 4 Indonesia 249865631\n", "4 5 Brazil 200361925\n", "\n", "[5 rows x 3 columns]" ] } ], "prompt_number": 1 }, { "cell_type": "markdown", "metadata": {}, "source": [ "Q: What is the relationship between `s` and the population of China?\n", "\n", " s = sum(df[df[1].str.startswith('C')][2])\n", " \n", "1. `s` is **greater** than the population of China\n", "1. `s` is the **same** as the population of China\n", "1. `s` is **less** than the population of China\n", "1. `s` is not a number.\n", "\n" ] }, { "cell_type": "code", "collapsed": false, "input": [ "from pandas import DataFrame, Series, Index\n", "import numpy as np\n", "\n", "s1 = Series(np.arange(1,4))\n", "s1" ], "language": "python", "metadata": {}, "outputs": [ { "metadata": {}, "output_type": "pyout", "prompt_number": 2, "text": [ "0 1\n", "1 2\n", "2 3\n", "dtype: int64" ] } ], "prompt_number": 2 }, { "cell_type": "markdown", "metadata": {}, "source": [ "Q: What is\n", " \n", " s1.apply(lambda k: 2*k).sum()\n", " " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Q: What is `s1.cumsum()[1]`?" ] }, { "cell_type": "code", "collapsed": false, "input": [], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 2 } ], "metadata": {} } ] }