{ "metadata": { "name": "", "signature": "sha256:0350ecdf81327697c728d70794ee100561e7ed49a11bc91b283bce648c6d7052" }, "nbformat": 3, "nbformat_minor": 0, "worksheets": [ { "cells": [ { "cell_type": "code", "collapsed": false, "input": [ "import matplotlib.pyplot as plt\n", "import numpy as np\n", "from goodies import as_table\n", "\n", "%matplotlib inline" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 1 }, { "cell_type": "code", "collapsed": false, "input": [ "import sqlite3\n", "\n", "sql_query = \"\"\"\n", "SELECT country1, teams.title as country2, winner \n", "FROM ( SELECT teams.title as country1, team2_id, winner \n", " FROM (SELECT team1_id, team2_id, winner \n", " FROM games \n", " INNER JOIN rounds on games.round_id=rounds.id \n", " WHERE rounds.title='Final') t1 \n", " INNER JOIN teams on teams.id=t1.team1_id) t2 \n", "INNER JOIN teams on teams.id=t2.team2_id;\n", "\"\"\"\n", "\n", "db = sqlite3.connect('../data/worldcup.db')\n", "cur = db.execute(sql_query)\n", "\n", "arr = np.fromiter(cur, dtype=[('country1', 'S30'),\n", " ('country2', 'S30'),\n", " ('winner', 'i2')])\n", "\n", "arr['country1'] = np.char.replace(arr['country1'], 'West Germany (-1989)', 'Germany')\n", "arr['country2'] = np.char.replace(arr['country2'], 'West Germany (-1989)', 'Germany')" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 2 }, { "cell_type": "code", "collapsed": false, "input": [ "as_table(arr, maxrows=100)" ], "language": "python", "metadata": {}, "outputs": [ { "html": [ "
country1 | country2 | winner |
---|---|---|
Uruguay | Argentina | 1 |
Italy | Czechoslovakia (-1992) | 1 |
Hungary | Italy | 2 |
Hungary | Germany | 2 |
Sweden | Brazil | 2 |
Brazil | Czechoslovakia (-1992) | 1 |
England | Germany | 1 |
Brazil | Italy | 1 |
Netherlands | Germany | 2 |
Netherlands | Argentina | 2 |
Italy | Germany | 1 |
Argentina | Germany | 1 |
Germany | Argentina | 1 |
Brazil | Italy | 1 |
Brazil | France | 2 |
Germany | Brazil | 2 |
Italy | France | 1 |
Netherlands | Spain | 2 |
Germany | Argentina | 1 |