GeezerVison is showing github.com — more snippiots · adelzaitri/code_py@d2d611d
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboard File renamed without changes. Collapse file Copy file name to clipboard +298Lines changed: 298 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +{ | | 2 | + "metadata": { | | 3 | + "name": "", | | 4 | + "signature": "sha256:d7e5db7147616b61d130ddfdd921a96d5276198a33e417481c36d81f3faa06c0" | | 5 | + }, | | 6 | + "nbformat": 3, | | 7 | + "nbformat_minor": 0, | | 8 | + "worksheets": [ | | 9 | + { | | 10 | + "cells": [ | | 11 | + { | | 12 | + "cell_type": "markdown", | | 13 | + "metadata": {}, | | 14 | + "source": [ | | 15 | + "# Battle of Five Kings Dataset\n", | | 16 | + "\n", | | 17 | + "This snippit was written by [Chris R. Albon](http://www.chrisralbon.com/) and is part of his collection of [well-documented Python snippits](https://github.com/chrisalbon/code_py). All code is written in Python 3 in iPython notebook and offered under the [Creative Commons Attribution-ShareAlike 4.0 International License](http://creativecommons.org/licenses/by-sa/4.0/).\n", | | 18 | + "\n", | | 19 | + "Based on: https://github.com/chrisalbon/war_of_the_five_kings_dataset" | | 20 | + ] | | 21 | + }, | | 22 | + { | | 23 | + "cell_type": "code", | | 24 | + "collapsed": false, | | 25 | + "input": [ | | 26 | + "# Import modules\n", | | 27 | + "import pandas as pd\n", | | 28 | + "\n", | | 29 | + "# Set ipython's max row display\n", | | 30 | + "pd.set_option('display.max_row', 1000)\n", | | 31 | + "\n", | | 32 | + "# Set iPython's max column width to 50\n", | | 33 | + "pd.set_option('display.max_columns', 50)" | | 34 | + ], | | 35 | + "language": "python", | | 36 | + "metadata": {}, | | 37 | + "outputs": [], | | 38 | + "prompt_number": 6 | | 39 | + }, | | 40 | + { | | 41 | + "cell_type": "code", | | 42 | + "collapsed": false, | | 43 | + "input": [ | | 44 | + "df = pd.read_csv('https://www.dropbox.com/s/52cb7kcflr8qm2u/5kings_battles_v1.csv?dl=1')\n", | | 45 | + "df.head()" | | 46 | + ], | | 47 | + "language": "python", | | 48 | + "metadata": {}, | | 49 | + "outputs": [ | | 50 | + { | | 51 | + "html": [ | | 52 | + "<div style=\"max-height:1000px;max-width:1500px;overflow:auto;\">\n", | | 53 | + "<table border=\"1\" class=\"dataframe\">\n", | | 54 | + " <thead>\n", | | 55 | + " <tr style=\"text-align: right;\">\n", | | 56 | + " <th></th>\n", | | 57 | + " <th>name</th>\n", | | 58 | + " <th>year</th>\n", | | 59 | + " <th>battle_number</th>\n", | | 60 | + " <th>attacker_king</th>\n", | | 61 | + " <th>defender_king</th>\n", | | 62 | + " <th>attacker_1</th>\n", | | 63 | + " <th>attacker_2</th>\n", | | 64 | + " <th>attacker_3</th>\n", | | 65 | + " <th>attacker_4</th>\n", | | 66 | + " <th>defender_1</th>\n", | | 67 | + " <th>defender_2</th>\n", | | 68 | + " <th>defender_3</th>\n", | | 69 | + " <th>defender_4</th>\n", | | 70 | + " <th>attacker_outcome</th>\n", | | 71 | + " <th>battle_type</th>\n", | | 72 | + " <th>major_death</th>\n", | | 73 | + " <th>major_capture</th>\n", | | 74 | + " <th>attacker_size</th>\n", | | 75 | + " <th>defender_size</th>\n", | | 76 | + " <th>attacker_commander</th>\n", | | 77 | + " <th>defender_commander</th>\n", | | 78 | + " <th>summer</th>\n", | | 79 | + " <th>location</th>\n", | | 80 | + " <th>region</th>\n", | | 81 | + " <th>note</th>\n", | | 82 | + " </tr>\n", | | 83 | + " </thead>\n", | | 84 | + " <tbody>\n", | | 85 | + " <tr>\n", | | 86 | + " <th>0</th>\n", | | 87 | + " <td> Battle of the Golden Tooth</td>\n", | | 88 | + " <td> 298</td>\n", | | 89 | + " <td> 1</td>\n", | | 90 | + " <td> Joffrey/Tommen Baratheon</td>\n", | | 91 | + " <td> Robb Stark</td>\n", | | 92 | + " <td> Lannister</td>\n", | | 93 | + " <td> NaN</td>\n", | | 94 | + " <td> NaN</td>\n", | | 95 | + " <td> NaN</td>\n", | | 96 | + " <td> Tully</td>\n", | | 97 | + " <td> NaN</td>\n", | | 98 | + " <td>NaN</td>\n", | | 99 | + " <td>NaN</td>\n", | | 100 | + " <td> win</td>\n", | | 101 | + " <td> pitched battle</td>\n", | | 102 | + " <td> 1</td>\n", | | 103 | + " <td> 0</td>\n", | | 104 | + " <td> 15000</td>\n", | | 105 | + " <td> 4000</td>\n", | | 106 | + " <td> Jaime Lannister</td>\n", | | 107 | + " <td> Clement Piper, Vance</td>\n", | | 108 | + " <td> 1</td>\n", | | 109 | + " <td> Golden Tooth</td>\n", | | 110 | + " <td> The Westerlands</td>\n", | | 111 | + " <td> NaN</td>\n", | | 112 | + " </tr>\n", | | 113 | + " <tr>\n", | | 114 | + " <th>1</th>\n", | | 115 | + " <td> Battle at the Mummer's Ford</td>\n", | | 116 | + " <td> 298</td>\n", | | 117 | + " <td> 2</td>\n", | | 118 | + " <td> Joffrey/Tommen Baratheon</td>\n", | | 119 | + " <td> Robb Stark</td>\n", | | 120 | + " <td> Lannister</td>\n", | | 121 | + " <td> NaN</td>\n", | | 122 | + " <td> NaN</td>\n", | | 123 | + " <td> NaN</td>\n", | | 124 | + " <td> Baratheon</td>\n", | | 125 | + " <td> NaN</td>\n", | | 126 | + " <td>NaN</td>\n", | | 127 | + " <td>NaN</td>\n", | | 128 | + " <td> win</td>\n", | | 129 | + " <td> ambush</td>\n", | | 130 | + " <td> 1</td>\n", | | 131 | + " <td> 0</td>\n", | | 132 | + " <td> NaN</td>\n", | | 133 | + " <td> 120</td>\n", | | 134 | + " <td> Gregor Clegane</td>\n", | | 135 | + " <td> Beric Dondarrion</td>\n", | | 136 | + " <td> 1</td>\n", | | 137 | + " <td> Mummer's Ford</td>\n", | | 138 | + " <td> The Riverlands</td>\n", | | 139 | + " <td> NaN</td>\n", | | 140 | + " </tr>\n", | | 141 | + " <tr>\n", | | 142 | + " <th>2</th>\n", | | 143 | + " <td> Battle of Riverrun</td>\n", | | 144 | + " <td> 298</td>\n", | | 145 | + " <td> 3</td>\n", | | 146 | + " <td> Joffrey/Tommen Baratheon</td>\n", | | 147 | + " <td> Robb Stark</td>\n", | | 148 | + " <td> Lannister</td>\n", | | 149 | + " <td> NaN</td>\n", | | 150 | + " <td> NaN</td>\n", | | 151 | + " <td> NaN</td>\n", | | 152 | + " <td> Tully</td>\n", | | 153 | + " <td> NaN</td>\n", | | 154 | + " <td>NaN</td>\n", | | 155 | + " <td>NaN</td>\n", | | 156 | + " <td> win</td>\n", | | 157 | + " <td> pitched battle</td>\n", | | 158 | + " <td> 0</td>\n", | | 159 | + " <td> 1</td>\n", | | 160 | + " <td> 15000</td>\n", | | 161 | + " <td> 10000</td>\n", | | 162 | + " <td> Jaime Lannister, Andros Brax</td>\n", | | 163 | + " <td> Edmure Tully, Tytos Blackwood</td>\n", | | 164 | + " <td> 1</td>\n", | | 165 | + " <td> Riverrun</td>\n", | | 166 | + " <td> The Riverlands</td>\n", | | 167 | + " <td> NaN</td>\n", | | 168 | + " </tr>\n", | | 169 | + " <tr>\n", | | 170 | + " <th>3</th>\n", | | 171 | + " <td> Battle of the Green Fork</td>\n", | | 172 | + " <td> 298</td>\n", | | 173 | + " <td> 4</td>\n", | | 174 | + " <td> Robb Stark</td>\n", | | 175 | + " <td> Joffrey/Tommen Baratheon</td>\n", | | 176 | + " <td> Stark</td>\n", | | 177 | + " <td> NaN</td>\n", | | 178 | + " <td> NaN</td>\n", | | 179 | + " <td> NaN</td>\n", | | 180 | + " <td> Lannister</td>\n", | | 181 | + " <td> NaN</td>\n", | | 182 | + " <td>NaN</td>\n", | | 183 | + " <td>NaN</td>\n", | | 184 | + " <td> loss</td>\n", | | 185 | + " <td> pitched battle</td>\n", | | 186 | + " <td> 1</td>\n", | | 187 | + " <td> 1</td>\n", | | 188 | + " <td> 18000</td>\n", | | 189 | + " <td> 20000</td>\n", | | 190 | + " <td> Roose Bolton, Wylis Manderly, Medger Cerwyn, H...</td>\n", | | 191 | + " <td> Tywin Lannister, Gregor Clegane, Kevan Lannist...</td>\n", | | 192 | + " <td> 1</td>\n", | | 193 | + " <td> Green Fork</td>\n", | | 194 | + " <td> The Riverlands</td>\n", | | 195 | + " <td> NaN</td>\n", | | 196 | + " </tr>\n", | | 197 | + " <tr>\n", | | 198 | + " <th>4</th>\n", | | 199 | + " <td> Battle of the Whispering Wood</td>\n", | | 200 | + " <td> 298</td>\n", | | 201 | + " <td> 5</td>\n", | | 202 | + " <td> Robb Stark</td>\n", | | 203 | + " <td> Joffrey/Tommen Baratheon</td>\n", | | 204 | + " <td> Stark</td>\n", | | 205 | + " <td> Tully</td>\n", | | 206 | + " <td> NaN</td>\n", | | 207 | + " <td> NaN</td>\n", | | 208 | + " <td> Lannister</td>\n", | | 209 | + " <td> NaN</td>\n", | | 210 | + " <td>NaN</td>\n", | | 211 | + " <td>NaN</td>\n", | | 212 | + " <td> win</td>\n", | | 213 | + " <td> ambush</td>\n", | | 214 | + " <td> 1</td>\n", | | 215 | + " <td> 1</td>\n", | | 216 | + " <td> 1875</td>\n", | | 217 | + " <td> 6000</td>\n", | | 218 | + " <td> Robb Stark, Brynden Tully</td>\n", | | 219 | + " <td> Jaime Lannister</td>\n", | | 220 | + " <td> 1</td>\n", | | 221 | + " <td> Whispering Wood</td>\n", | | 222 | + " <td> The Riverlands</td>\n", | | 223 | + " <td> NaN</td>\n", | | 224 | + " </tr>\n", | | 225 | + " </tbody>\n", | | 226 | + "</table>\n", | | 227 | + "</div>" | | 228 | + ], | | 229 | + "metadata": {}, | | 230 | + "output_type": "pyout", | | 231 | + "prompt_number": 7, | | 232 | + "text": [ | | 233 | + " name year battle_number \\\n", | | 234 | + "0 Battle of the Golden Tooth 298 1 \n", | | 235 | + "1 Battle at the Mummer's Ford 298 2 \n", | | 236 | + "2 Battle of Riverrun 298 3 \n", | | 237 | + "3 Battle of the Green Fork 298 4 \n", | | 238 | + "4 Battle of the Whispering Wood 298 5 \n", | | 239 | + "\n", | | 240 | + " attacker_king defender_king attacker_1 attacker_2 \\\n", | | 241 | + "0 Joffrey/Tommen Baratheon Robb Stark Lannister NaN \n", | | 242 | + "1 Joffrey/Tommen Baratheon Robb Stark Lannister NaN \n", | | 243 | + "2 Joffrey/Tommen Baratheon Robb Stark Lannister NaN \n", | | 244 | + "3 Robb Stark Joffrey/Tommen Baratheon Stark NaN \n", | | 245 | + "4 Robb Stark Joffrey/Tommen Baratheon Stark Tully \n", | | 246 | + "\n", | | 247 | + " attacker_3 attacker_4 defender_1 defender_2 defender_3 defender_4 \\\n", | | 248 | + "0 NaN NaN Tully NaN NaN NaN \n", | | 249 | + "1 NaN NaN Baratheon NaN NaN NaN \n", | | 250 | + "2 NaN NaN Tully NaN NaN NaN \n", | | 251 | + "3 NaN NaN Lannister NaN NaN NaN \n", | | 252 | + "4 NaN NaN Lannister NaN NaN NaN \n", | | 253 | + "\n", | | 254 | + " attacker_outcome battle_type major_death major_capture attacker_size \\\n", | | 255 | + "0 win pitched battle 1 0 15000 \n", | | 256 | + "1 win ambush 1 0 NaN \n", | | 257 | + "2 win pitched battle 0 1 15000 \n", | | 258 | + "3 loss pitched battle 1 1 18000 \n", | | 259 | + "4 win ambush 1 1 1875 \n", | | 260 | + "\n", | | 261 | + " defender_size attacker_commander \\\n", | | 262 | + "0 4000 Jaime Lannister \n", | | 263 | + "1 120 Gregor Clegane \n", | | 264 | + "2 10000 Jaime Lannister, Andros Brax \n", | | 265 | + "3 20000 Roose Bolton, Wylis Manderly, Medger Cerwyn, H... \n", | | 266 | + "4 6000 Robb Stark, Brynden Tully \n", | | 267 | + "\n", | | 268 | + " defender_commander summer location \\\n", | | 269 | + "0 Clement Piper, Vance 1 Golden Tooth \n", | | 270 | + "1 Beric Dondarrion 1 Mummer's Ford \n", | | 271 | + "2 Edmure Tully, Tytos Blackwood 1 Riverrun \n", | | 272 | + "3 Tywin Lannister, Gregor Clegane, Kevan Lannist... 1 Green Fork \n", | | 273 | + "4 Jaime Lannister 1 Whispering Wood \n", | | 274 | + "\n", | | 275 | + " region note \n", | | 276 | + "0 The Westerlands NaN \n", | | 277 | + "1 The Riverlands NaN \n", | | 278 | + "2 The Riverlands NaN \n", | | 279 | + "3 The Riverlands NaN \n", | | 280 | + "4 The Riverlands NaN " | | 281 | + ] | | 282 | + } | | 283 | + ], | | 284 | + "prompt_number": 7 | | 285 | + }, | | 286 | + { | | 287 | + "cell_type": "code", | | 288 | + "collapsed": false, | | 289 | + "input": [], | | 290 | + "language": "python", | | 291 | + "metadata": {}, | | 292 | + "outputs": [] | | 293 | + } | | 294 | + ], | | 295 | + "metadata": {} | | 296 | + } | | 297 | + ] | | 298 | +} |
|