Skip to content
AKON Data Overview.ipynb 56.1 KiB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000
{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# AKON Metadata - Data Overview"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "*Get a first impression of the postcard metadata*"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Setup"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Using the [Pandas Python Data Analysis Library](https://pandas.pydata.org/).\n",
    "\n",
    "For an intro to pandas feel free to take a look at this [Workshop for CBioVikings](https://github.com/dblyon/PandasIntro) by David Lyon."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Load Data"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "`df` stands for *Data Frame*"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "df = pd.read_csv('akon_postcards_public_domain.csv.bz2')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## View Data"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Rough Overview"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "How much datasets are in there?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "28882"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(df)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "What does a dataset look like?\n",
    "Show me the first one!"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Unnamed: 0</th>\n",
       "      <th>akon_id</th>\n",
       "      <th>id</th>\n",
       "      <th>altitude</th>\n",
       "      <th>building</th>\n",
       "      <th>city</th>\n",
       "      <th>color</th>\n",
       "      <th>comment</th>\n",
       "      <th>mountain</th>\n",
       "      <th>other</th>\n",
       "      <th>...</th>\n",
       "      <th>date</th>\n",
       "      <th>feature_class</th>\n",
       "      <th>feature_code</th>\n",
       "      <th>geoname_id</th>\n",
       "      <th>latitude</th>\n",
       "      <th>longitude</th>\n",
       "      <th>name</th>\n",
       "      <th>country_id</th>\n",
       "      <th>admin_name_1</th>\n",
       "      <th>admin_code_1</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>AK111_024</td>\n",
       "      <td>74685</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Kierling</td>\n",
       "      <td>True</td>\n",
       "      <td>1908</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>...</td>\n",
       "      <td>gelaufen 1908</td>\n",
       "      <td>P</td>\n",
       "      <td>PPL</td>\n",
       "      <td>2774449.0</td>\n",
       "      <td>48.30997</td>\n",
       "      <td>16.27616</td>\n",
       "      <td>Kierling</td>\n",
       "      <td>AT</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>1 rows × 29 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "   Unnamed: 0    akon_id     id  altitude building      city  color comment  \\\n",
       "0           0  AK111_024  74685       NaN      NaN  Kierling   True    1908   \n",
       "\n",
       "  mountain other     ...                date feature_class feature_code  \\\n",
       "0      NaN   NaN     ...       gelaufen 1908             P          PPL   \n",
       "\n",
       "  geoname_id  latitude  longitude      name country_id admin_name_1  \\\n",
       "0  2774449.0  48.30997   16.27616  Kierling         AT          NaN   \n",
       "\n",
       "  admin_code_1  \n",
       "0          NaN  \n",
       "\n",
       "[1 rows x 29 columns]"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.head(1)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "There seem to be a few columns missing from the output. Let's fix that by setting pandas output options:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "pd.set_option('display.max_columns', 100)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Let's try again:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Unnamed: 0</th>\n",
       "      <th>akon_id</th>\n",
       "      <th>id</th>\n",
       "      <th>altitude</th>\n",
       "      <th>building</th>\n",
       "      <th>city</th>\n",
       "      <th>color</th>\n",
       "      <th>comment</th>\n",
       "      <th>mountain</th>\n",
       "      <th>other</th>\n",
       "      <th>photographer</th>\n",
       "      <th>publisher</th>\n",
       "      <th>publisher_place</th>\n",
       "      <th>region</th>\n",
       "      <th>water_body</th>\n",
       "      <th>year</th>\n",
       "      <th>inventory_number</th>\n",
       "      <th>signature</th>\n",
       "      <th>revision_date</th>\n",
       "      <th>date</th>\n",
       "      <th>feature_class</th>\n",
       "      <th>feature_code</th>\n",
       "      <th>geoname_id</th>\n",
       "      <th>latitude</th>\n",
       "      <th>longitude</th>\n",
       "      <th>name</th>\n",
       "      <th>country_id</th>\n",
       "      <th>admin_name_1</th>\n",
       "      <th>admin_code_1</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>AK111_024</td>\n",
       "      <td>74685</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Kierling</td>\n",
       "      <td>True</td>\n",
       "      <td>1908</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Geogr. Topogr. Bilder-Samml. 1944, 6380</td>\n",
       "      <td>2014-09-05 10:13:12.536</td>\n",
       "      <td>gelaufen 1908</td>\n",
       "      <td>P</td>\n",
       "      <td>PPL</td>\n",
       "      <td>2774449.0</td>\n",
       "      <td>48.30997</td>\n",
       "      <td>16.27616</td>\n",
       "      <td>Kierling</td>\n",
       "      <td>AT</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Unnamed: 0    akon_id     id  altitude building      city  color comment  \\\n",
       "0           0  AK111_024  74685       NaN      NaN  Kierling   True    1908   \n",
       "\n",
       "  mountain other photographer publisher publisher_place region water_body  \\\n",
       "0      NaN   NaN          NaN       NaN             NaN    NaN        NaN   \n",
       "\n",
       "   year inventory_number                                signature  \\\n",
       "0   NaN              NaN  Geogr. Topogr. Bilder-Samml. 1944, 6380   \n",
       "\n",
       "             revision_date           date feature_class feature_code  \\\n",
       "0  2014-09-05 10:13:12.536  gelaufen 1908             P          PPL   \n",
       "\n",
       "   geoname_id  latitude  longitude      name country_id admin_name_1  \\\n",
       "0   2774449.0  48.30997   16.27616  Kierling         AT          NaN   \n",
       "\n",
       "  admin_code_1  \n",
       "0          NaN  "
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.head(1)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Now we see all columns."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "What are all the columns called again?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Index(['Unnamed: 0', 'akon_id', 'id', 'altitude', 'building', 'city', 'color',\n",
       "       'comment', 'mountain', 'other', 'photographer', 'publisher',\n",
       "       'publisher_place', 'region', 'water_body', 'year', 'inventory_number',\n",
       "       'signature', 'revision_date', 'date', 'feature_class', 'feature_code',\n",
       "       'geoname_id', 'latitude', 'longitude', 'name', 'country_id',\n",
       "       'admin_name_1', 'admin_code_1'],\n",
       "      dtype='object')"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.columns"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Show Random Entries"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Show me 3 random entries:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Unnamed: 0</th>\n",
       "      <th>akon_id</th>\n",
       "      <th>id</th>\n",
       "      <th>altitude</th>\n",
       "      <th>building</th>\n",
       "      <th>city</th>\n",
       "      <th>color</th>\n",
       "      <th>comment</th>\n",
       "      <th>mountain</th>\n",
       "      <th>other</th>\n",
       "      <th>photographer</th>\n",
       "      <th>publisher</th>\n",
       "      <th>publisher_place</th>\n",
       "      <th>region</th>\n",
       "      <th>water_body</th>\n",
       "      <th>year</th>\n",
       "      <th>inventory_number</th>\n",
       "      <th>signature</th>\n",
       "      <th>revision_date</th>\n",
       "      <th>date</th>\n",
       "      <th>feature_class</th>\n",
       "      <th>feature_code</th>\n",
       "      <th>geoname_id</th>\n",
       "      <th>latitude</th>\n",
       "      <th>longitude</th>\n",
       "      <th>name</th>\n",
       "      <th>country_id</th>\n",
       "      <th>admin_name_1</th>\n",
       "      <th>admin_code_1</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>458</th>\n",
       "      <td>458</td>\n",
       "      <td>AK114_189</td>\n",
       "      <td>76614</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Airolo</td>\n",
       "      <td>True</td>\n",
       "      <td>1909 gel</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Geogr. Topogr. Bilder-Samml. 1944, 27</td>\n",
       "      <td>2014-09-09 08:50:37.905</td>\n",
       "      <td>gelaufen 1909</td>\n",
       "      <td>P</td>\n",
       "      <td>PPL</td>\n",
       "      <td>2661830.0</td>\n",
       "      <td>46.52847</td>\n",
       "      <td>8.60881</td>\n",
       "      <td>Airolo</td>\n",
       "      <td>CH</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24510</th>\n",
       "      <td>24510</td>\n",
       "      <td>AK075_467</td>\n",
       "      <td>46922</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Klausen</td>\n",
       "      <td>False</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1913.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2014-08-21 10:05:32.779</td>\n",
       "      <td>1913</td>\n",
       "      <td>P</td>\n",
       "      <td>PPLA3</td>\n",
       "      <td>3178764.0</td>\n",
       "      <td>46.64001</td>\n",
       "      <td>11.56573</td>\n",
       "      <td>Klausen</td>\n",
       "      <td>IT</td>\n",
       "      <td>Südtirol</td>\n",
       "      <td>17</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18564</th>\n",
       "      <td>18564</td>\n",
       "      <td>AK082_546</td>\n",
       "      <td>51980</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Velsen</td>\n",
       "      <td>False</td>\n",
       "      <td>v 1905</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2014-08-25 17:46:23.417</td>\n",
       "      <td>vor 1905</td>\n",
       "      <td>P</td>\n",
       "      <td>PPL</td>\n",
       "      <td>2745673.0</td>\n",
       "      <td>52.46000</td>\n",
       "      <td>4.65000</td>\n",
       "      <td>Velsen</td>\n",
       "      <td>NL</td>\n",
       "      <td>Nord-Holland</td>\n",
       "      <td>07</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       Unnamed: 0    akon_id     id  altitude building     city  color  \\\n",
       "458           458  AK114_189  76614       NaN      NaN   Airolo   True   \n",
       "24510       24510  AK075_467  46922       NaN      NaN  Klausen  False   \n",
       "18564       18564  AK082_546  51980       NaN      NaN   Velsen  False   \n",
       "\n",
       "        comment mountain other photographer publisher publisher_place region  \\\n",
       "458    1909 gel      NaN   NaN          NaN       NaN             NaN    NaN   \n",
       "24510       NaN      NaN   NaN          NaN       NaN             NaN    NaN   \n",
       "18564    v 1905      NaN   NaN          NaN       NaN             NaN    NaN   \n",
       "\n",
       "      water_body    year inventory_number  \\\n",
       "458          NaN     NaN              NaN   \n",
       "24510        NaN  1913.0              NaN   \n",
       "18564        NaN     NaN              NaN   \n",
       "\n",
       "                                   signature            revision_date  \\\n",
       "458    Geogr. Topogr. Bilder-Samml. 1944, 27  2014-09-09 08:50:37.905   \n",
       "24510                                    NaN  2014-08-21 10:05:32.779   \n",
       "18564                                    NaN  2014-08-25 17:46:23.417   \n",
       "\n",
       "                date feature_class feature_code  geoname_id  latitude  \\\n",
       "458    gelaufen 1909             P          PPL   2661830.0  46.52847   \n",
       "24510           1913             P        PPLA3   3178764.0  46.64001   \n",
       "18564       vor 1905             P          PPL   2745673.0  52.46000   \n",
       "\n",
       "       longitude     name country_id  admin_name_1 admin_code_1  \n",
       "458      8.60881   Airolo         CH           NaN          NaN  \n",
       "24510   11.56573  Klausen         IT      Südtirol           17  \n",
       "18564    4.65000   Velsen         NL  Nord-Holland           07  "
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.sample(3)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Calling `sample` again yields different entries:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Unnamed: 0</th>\n",
       "      <th>akon_id</th>\n",
       "      <th>id</th>\n",
       "      <th>altitude</th>\n",
       "      <th>building</th>\n",
       "      <th>city</th>\n",
       "      <th>color</th>\n",
       "      <th>comment</th>\n",
       "      <th>mountain</th>\n",
       "      <th>other</th>\n",
       "      <th>photographer</th>\n",
       "      <th>publisher</th>\n",
       "      <th>publisher_place</th>\n",
       "      <th>region</th>\n",
       "      <th>water_body</th>\n",
       "      <th>year</th>\n",
       "      <th>inventory_number</th>\n",
       "      <th>signature</th>\n",
       "      <th>revision_date</th>\n",
       "      <th>date</th>\n",
       "      <th>feature_class</th>\n",
       "      <th>feature_code</th>\n",
       "      <th>geoname_id</th>\n",
       "      <th>latitude</th>\n",
       "      <th>longitude</th>\n",
       "      <th>name</th>\n",
       "      <th>country_id</th>\n",
       "      <th>admin_name_1</th>\n",
       "      <th>admin_code_1</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>27658</th>\n",
       "      <td>27658</td>\n",
       "      <td>AK097_351</td>\n",
       "      <td>62277</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Station Brenner</td>\n",
       "      <td>Steinach am Brenner</td>\n",
       "      <td>False</td>\n",
       "      <td>1905 gel</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2014-09-02 11:15:45.988</td>\n",
       "      <td>vor 1905</td>\n",
       "      <td>P</td>\n",
       "      <td>PPLA3</td>\n",
       "      <td>2764557.0</td>\n",
       "      <td>47.08333</td>\n",
       "      <td>11.46667</td>\n",
       "      <td>Steinach am Brenner</td>\n",
       "      <td>AT</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14993</th>\n",
       "      <td>14993</td>\n",
       "      <td>AK021_515</td>\n",
       "      <td>12604</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Gross-Pöchlarn, Klein-Pöchlarn</td>\n",
       "      <td>False</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Ledermann</td>\n",
       "      <td>Wien</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1917.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2014-08-04 07:59:10.136</td>\n",
       "      <td>1917</td>\n",
       "      <td>P</td>\n",
       "      <td>PPLA3</td>\n",
       "      <td>2768627.0</td>\n",
       "      <td>48.20000</td>\n",
       "      <td>15.20000</td>\n",
       "      <td>Pöchlarn</td>\n",
       "      <td>AT</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15934</th>\n",
       "      <td>15934</td>\n",
       "      <td>AK025_596</td>\n",
       "      <td>15102</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Pfarrkirche</td>\n",
       "      <td>Mondsee</td>\n",
       "      <td>False</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1914.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2014-08-04 07:59:10.187</td>\n",
       "      <td>1914</td>\n",
       "      <td>P</td>\n",
       "      <td>PPLA3</td>\n",
       "      <td>2771277.0</td>\n",
       "      <td>47.85648</td>\n",
       "      <td>13.34908</td>\n",
       "      <td>Mondsee</td>\n",
       "      <td>AT</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       Unnamed: 0    akon_id     id  altitude         building  \\\n",
       "27658       27658  AK097_351  62277       NaN  Station Brenner   \n",
       "14993       14993  AK021_515  12604       NaN              NaN   \n",
       "15934       15934  AK025_596  15102       NaN      Pfarrkirche   \n",
       "\n",
       "                                 city  color   comment mountain other  \\\n",
       "27658             Steinach am Brenner  False  1905 gel      NaN   NaN   \n",
       "14993  Gross-Pöchlarn, Klein-Pöchlarn  False       NaN      NaN   NaN   \n",
       "15934                         Mondsee  False       NaN      NaN   NaN   \n",
       "\n",
       "      photographer  publisher publisher_place region water_body    year  \\\n",
       "27658          NaN        NaN             NaN    NaN        NaN     NaN   \n",
       "14993          NaN  Ledermann            Wien    NaN        NaN  1917.0   \n",
       "15934          NaN        NaN             NaN    NaN        NaN  1914.0   \n",
       "\n",
       "      inventory_number signature            revision_date      date  \\\n",
       "27658              NaN       NaN  2014-09-02 11:15:45.988  vor 1905   \n",
       "14993              NaN       NaN  2014-08-04 07:59:10.136      1917   \n",
       "15934              NaN       NaN  2014-08-04 07:59:10.187      1914   \n",
       "\n",
       "      feature_class feature_code  geoname_id  latitude  longitude  \\\n",
       "27658             P        PPLA3   2764557.0  47.08333   11.46667   \n",
       "14993             P        PPLA3   2768627.0  48.20000   15.20000   \n",
       "15934             P        PPLA3   2771277.0  47.85648   13.34908   \n",
       "\n",
       "                      name country_id admin_name_1 admin_code_1  \n",
       "27658  Steinach am Brenner         AT          NaN          NaN  \n",
       "14993             Pöchlarn         AT          NaN          NaN  \n",
       "15934              Mondsee         AT          NaN          NaN  "
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.sample(3)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Count Things"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "How many entries show things in Italy?\n",
    "\n",
    "Let's use the `country_id` for this question:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "df_in_italy = df[df['country_id'] == 'IT']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2983"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(df_in_italy)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "How many postcards are in color?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "df_in_color = df[df['color'] == True]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "7075"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(df_in_color)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Can I do this in one line?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "7075"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(df[df['color'] == True])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "How many different publisher places are in the data set?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1324"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(df['publisher_place'].unique())"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Show me some!"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "ename": "AttributeError",
     "evalue": "'numpy.ndarray' object has no attribute 'sample'",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mAttributeError\u001b[0m                            Traceback (most recent call last)",
      "\u001b[0;32m<ipython-input-21-3d3e9c7ad7b5>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mdf\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'publisher_place'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0munique\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msample\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m10\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[0;31mAttributeError\u001b[0m: 'numpy.ndarray' object has no attribute 'sample'"
     ]
    }
   ],
   "source": [
    "df['publisher_place'].unique().sample(10)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Oh, that doesn't work. Let's wrap it in a pandas DataFrame, step by step:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [],
   "source": [
    "publisher_places = df['publisher_place'].unique()"
   ]