{ "cells": [ { "cell_type": "markdown", "id": "8b32e524", "metadata": {}, "source": [ "# Data Frames and other iterables\n", "\n", "Today, we're going to explore {term}`DataFrame`s in greater detail. We'll continue using\n", "that same coffee dataset." ] }, { "cell_type": "code", "execution_count": 1, "id": "2edd1cdb", "metadata": {}, "outputs": [], "source": [ "import pandas as pd" ] }, { "cell_type": "code", "execution_count": 2, "id": "98e8535e", "metadata": {}, "outputs": [], "source": [ "coffee_data_url = 'https://raw.githubusercontent.com/jldbc/coffee-quality-database/master/data/robusta_data_cleaned.csv'" ] }, { "cell_type": "code", "execution_count": 3, "id": "80039de5", "metadata": {}, "outputs": [], "source": [ "coffee_df =pd.read_csv(coffee_data_url)" ] }, { "cell_type": "markdown", "id": "ef344709", "metadata": {}, "source": [ "```{important}\n", "A reason to use Jupyter is that it formats the output to be more readable. Compare the view of the DataFrame with jupyter and without. \n", "\n", "Jupyter uses the object's `to_html` method if it exists, where the `print` function casts the object to a string.\n", "```" ] }, { "cell_type": "code", "execution_count": 4, "id": "f5ade918", "metadata": {}, "outputs": [ { "data": { "text/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", " \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", " \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", " \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", " \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", " \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", " \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", " \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", " \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", " \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", " \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", " \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", " \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", " \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", " \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", " \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", " \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", "
Unnamed: 0SpeciesOwnerCountry.of.OriginFarm.NameLot.NumberMillICO.NumberCompanyAltitude...ColorCategory.Two.DefectsExpirationCertification.BodyCertification.AddressCertification.Contactunit_of_measurementaltitude_low_metersaltitude_high_metersaltitude_mean_meters
01Robustaankole coffee producers coopUgandakyangundu cooperative societyNaNankole coffee producers0ankole coffee producers coop1488...Green2June 26th, 2015Uganda Coffee Development Authoritye36d0270932c3b657e96b7b0278dfd85dc0fe74303077a1c6bac60e6f514691634a7f6eb5c85aae8m1488.01488.01488.0
12Robustanishant gurjerIndiasethuraman estate kaapi royale25sethuraman estate14/1148/2017/21kaapi royale3170...NaN2October 31st, 2018Specialty Coffee Associationff7c18ad303d4b603ac3f8cff7e611ffc735e720352d0cf7f3e9be14dad7df644ad65efc27605ae2m3170.03170.03170.0
23Robustaandrew hetzelIndiasethuraman estateNaNNaN0000sethuraman estate1000m...Green0April 29th, 2016Specialty Coffee Associationff7c18ad303d4b603ac3f8cff7e611ffc735e720352d0cf7f3e9be14dad7df644ad65efc27605ae2m1000.01000.01000.0
34RobustaugacofUgandaugacof project areaNaNugacof0ugacof ltd1212...Green7July 14th, 2015Uganda Coffee Development Authoritye36d0270932c3b657e96b7b0278dfd85dc0fe74303077a1c6bac60e6f514691634a7f6eb5c85aae8m1212.01212.01212.0
45Robustakatuka development trust ltdUgandakatikamu capca farmers associationNaNkatuka development trust0katuka development trust ltd1200-1300...Green3June 26th, 2015Uganda Coffee Development Authoritye36d0270932c3b657e96b7b0278dfd85dc0fe74303077a1c6bac60e6f514691634a7f6eb5c85aae8m1200.01300.01250.0
56Robustaandrew hetzelIndiaNaNNaN(self)NaNcafemakers, llc3000'...Green0February 28th, 2013Specialty Coffee Associationff7c18ad303d4b603ac3f8cff7e611ffc735e720352d0cf7f3e9be14dad7df644ad65efc27605ae2m3000.03000.03000.0
67Robustaandrew hetzelIndiasethuraman estatesNaNNaNNaNcafemakers750m...Green0May 15th, 2015Specialty Coffee Associationff7c18ad303d4b603ac3f8cff7e611ffc735e720352d0cf7f3e9be14dad7df644ad65efc27605ae2m750.0750.0750.0
78Robustanishant gurjerIndiasethuraman estate kaapi royale7sethuraman estate14/1148/2017/18kaapi royale3140...Bluish-Green0October 25th, 2018Specialty Coffee Associationff7c18ad303d4b603ac3f8cff7e611ffc735e720352d0cf7f3e9be14dad7df644ad65efc27605ae2m3140.03140.03140.0
89Robustanishant gurjerIndiasethuraman estateRKRsethuraman estate14/1148/2016/17kaapi royale1000...Green0August 17th, 2017Specialty Coffee Associationff7c18ad303d4b603ac3f8cff7e611ffc735e720352d0cf7f3e9be14dad7df644ad65efc27605ae2m1000.01000.01000.0
910RobustaugacofUgandaishakaNaNnsubuga umar0ugacof ltd900-1300...Green6August 5th, 2015Uganda Coffee Development Authoritye36d0270932c3b657e96b7b0278dfd85dc0fe74303077a1c6bac60e6f514691634a7f6eb5c85aae8m900.01300.01100.0
1011RobustaugacofUgandaugacof project areaNaNugacof0ugacof ltd1095...Green1June 26th, 2015Uganda Coffee Development Authoritye36d0270932c3b657e96b7b0278dfd85dc0fe74303077a1c6bac60e6f514691634a7f6eb5c85aae8m1095.01095.01095.0
1112Robustanishant gurjerIndiasethuraman estate kaapi royaleRC ABsethuraman estate14/1148/2016/12kaapi royale1000...Green0August 23rd, 2017Specialty Coffee Associationff7c18ad303d4b603ac3f8cff7e611ffc735e720352d0cf7f3e9be14dad7df644ad65efc27605ae2m1000.01000.01000.0
1213Robustaandrew hetzelIndiasethuraman estatesNaNNaNNaNcafemakers750m...Green1May 19th, 2015Specialty Coffee Associationff7c18ad303d4b603ac3f8cff7e611ffc735e720352d0cf7f3e9be14dad7df644ad65efc27605ae2m750.0750.0750.0
1314Robustakasozi coffee farmers associationUgandakasozi coffee farmersNaNNaN0kasozi coffee farmers association1367...Green7July 14th, 2015Uganda Coffee Development Authoritye36d0270932c3b657e96b7b0278dfd85dc0fe74303077a1c6bac60e6f514691634a7f6eb5c85aae8m1367.01367.01367.0
1415Robustaankole coffee producers coopUgandakyangundu coop societyNaNankole coffee producers coop union ltd0ankole coffee producers coop1488...Green2July 14th, 2015Uganda Coffee Development Authoritye36d0270932c3b657e96b7b0278dfd85dc0fe74303077a1c6bac60e6f514691634a7f6eb5c85aae8m1488.01488.01488.0
1516Robustaandrew hetzelIndiasethuraman estateNaNNaN0000sethuraman estate1000m...Green0April 29th, 2016Specialty Coffee Associationff7c18ad303d4b603ac3f8cff7e611ffc735e720352d0cf7f3e9be14dad7df644ad65efc27605ae2m1000.01000.01000.0
1617Robustaandrew hetzelIndiasethuraman estatesNaNsethuraman estatesNaNcafemakers, llc750m...Blue-Green0June 3rd, 2014Specialty Coffee Associationff7c18ad303d4b603ac3f8cff7e611ffc735e720352d0cf7f3e9be14dad7df644ad65efc27605ae2m750.0750.0750.0
1718Robustakawacom uganda ltdUgandabushenyiNaNkawacom0kawacom uganda ltd1600...Green1June 27th, 2015Uganda Coffee Development Authoritye36d0270932c3b657e96b7b0278dfd85dc0fe74303077a1c6bac60e6f514691634a7f6eb5c85aae8m1600.01600.01600.0
1819Robustanitubaasa ltdUgandakigezi coffee farmers associationNaNnitubaasa0nitubaasa ltd1745...Green2June 27th, 2015Uganda Coffee Development Authoritye36d0270932c3b657e96b7b0278dfd85dc0fe74303077a1c6bac60e6f514691634a7f6eb5c85aae8m1745.01745.01745.0
1920Robustamannya coffee projectUgandamannya coffee projectNaNmannya coffee project0mannya coffee project1200...Green1June 27th, 2015Uganda Coffee Development Authoritye36d0270932c3b657e96b7b0278dfd85dc0fe74303077a1c6bac60e6f514691634a7f6eb5c85aae8m1200.01200.01200.0
2021Robustaandrew hetzelIndiasethuraman estatesNaNNaNNaNcafemakers750m...Bluish-Green1May 19th, 2015Specialty Coffee Associationff7c18ad303d4b603ac3f8cff7e611ffc735e720352d0cf7f3e9be14dad7df644ad65efc27605ae2m750.0750.0750.0
2122Robustaandrew hetzelIndiasethuraman estatesNaNsethuraman estatesNaNcafemakers, llc750m...Green0June 20th, 2014Specialty Coffee Associationff7c18ad303d4b603ac3f8cff7e611ffc735e720352d0cf7f3e9be14dad7df644ad65efc27605ae2m750.0750.0750.0
2223Robustaandrew hetzelUnited Statessethuraman estatesNaNsethuraman estatesNaNcafemakers, llc3000'...Green0February 28th, 2013Specialty Coffee Associationff7c18ad303d4b603ac3f8cff7e611ffc735e720352d0cf7f3e9be14dad7df644ad65efc27605ae2m3000.03000.03000.0
2324Robustaluis roblesEcuadorrobustasaLavado 1our own labNaNrobustasaNaN...Blue-Green1January 18th, 2017Specialty Coffee Associationff7c18ad303d4b603ac3f8cff7e611ffc735e720352d0cf7f3e9be14dad7df644ad65efc27605ae2mNaNNaNNaN
2425Robustaluis roblesEcuadorrobustasaLavado 3own laboratoryNaNrobustasa40...Blue-Green0January 18th, 2017Specialty Coffee Associationff7c18ad303d4b603ac3f8cff7e611ffc735e720352d0cf7f3e9be14dad7df644ad65efc27605ae2m40.040.040.0
2526Robustajames mooreUnited Statesfazenda cazengoNaNcafe cazengoNaNglobal opportunity fund795 meters...NaN6December 23rd, 2015Specialty Coffee Associationff7c18ad303d4b603ac3f8cff7e611ffc735e720352d0cf7f3e9be14dad7df644ad65efc27605ae2m795.0795.0795.0
2627Robustacafe politicoIndiaNaNNaNNaN14-1118-2014-0087cafe politicoNaN...Green1August 25th, 2015Specialty Coffee Associationff7c18ad303d4b603ac3f8cff7e611ffc735e720352d0cf7f3e9be14dad7df644ad65efc27605ae2mNaNNaNNaN
2728Robustacafe politicoVietnamNaNNaNNaNNaNcafe politicoNaN...None9August 25th, 2015Specialty Coffee Associationff7c18ad303d4b603ac3f8cff7e611ffc735e720352d0cf7f3e9be14dad7df644ad65efc27605ae2mNaNNaNNaN
\n", "

28 rows × 44 columns

\n", "
" ], "text/plain": [ " Unnamed: 0 Species Owner Country.of.Origin \\\n", "0 1 Robusta ankole coffee producers coop Uganda \n", "1 2 Robusta nishant gurjer India \n", "2 3 Robusta andrew hetzel India \n", "3 4 Robusta ugacof Uganda \n", "4 5 Robusta katuka development trust ltd Uganda \n", "5 6 Robusta andrew hetzel India \n", "6 7 Robusta andrew hetzel India \n", "7 8 Robusta nishant gurjer India \n", "8 9 Robusta nishant gurjer India \n", "9 10 Robusta ugacof Uganda \n", "10 11 Robusta ugacof Uganda \n", "11 12 Robusta nishant gurjer India \n", "12 13 Robusta andrew hetzel India \n", "13 14 Robusta kasozi coffee farmers association Uganda \n", "14 15 Robusta ankole coffee producers coop Uganda \n", "15 16 Robusta andrew hetzel India \n", "16 17 Robusta andrew hetzel India \n", "17 18 Robusta kawacom uganda ltd Uganda \n", "18 19 Robusta nitubaasa ltd Uganda \n", "19 20 Robusta mannya coffee project Uganda \n", "20 21 Robusta andrew hetzel India \n", "21 22 Robusta andrew hetzel India \n", "22 23 Robusta andrew hetzel United States \n", "23 24 Robusta luis robles Ecuador \n", "24 25 Robusta luis robles Ecuador \n", "25 26 Robusta james moore United States \n", "26 27 Robusta cafe politico India \n", "27 28 Robusta cafe politico Vietnam \n", "\n", " Farm.Name Lot.Number \\\n", "0 kyangundu cooperative society NaN \n", "1 sethuraman estate kaapi royale 25 \n", "2 sethuraman estate NaN \n", "3 ugacof project area NaN \n", "4 katikamu capca farmers association NaN \n", "5 NaN NaN \n", "6 sethuraman estates NaN \n", "7 sethuraman estate kaapi royale 7 \n", "8 sethuraman estate RKR \n", "9 ishaka NaN \n", "10 ugacof project area NaN \n", "11 sethuraman estate kaapi royale RC AB \n", "12 sethuraman estates NaN \n", "13 kasozi coffee farmers NaN \n", "14 kyangundu coop society NaN \n", "15 sethuraman estate NaN \n", "16 sethuraman estates NaN \n", "17 bushenyi NaN \n", "18 kigezi coffee farmers association NaN \n", "19 mannya coffee project NaN \n", "20 sethuraman estates NaN \n", "21 sethuraman estates NaN \n", "22 sethuraman estates NaN \n", "23 robustasa Lavado 1 \n", "24 robustasa Lavado 3 \n", "25 fazenda cazengo NaN \n", "26 NaN NaN \n", "27 NaN NaN \n", "\n", " Mill ICO.Number \\\n", "0 ankole coffee producers 0 \n", "1 sethuraman estate 14/1148/2017/21 \n", "2 NaN 0000 \n", "3 ugacof 0 \n", "4 katuka development trust 0 \n", "5 (self) NaN \n", "6 NaN NaN \n", "7 sethuraman estate 14/1148/2017/18 \n", "8 sethuraman estate 14/1148/2016/17 \n", "9 nsubuga umar 0 \n", "10 ugacof 0 \n", "11 sethuraman estate 14/1148/2016/12 \n", "12 NaN NaN \n", "13 NaN 0 \n", "14 ankole coffee producers coop union ltd 0 \n", "15 NaN 0000 \n", "16 sethuraman estates NaN \n", "17 kawacom 0 \n", "18 nitubaasa 0 \n", "19 mannya coffee project 0 \n", "20 NaN NaN \n", "21 sethuraman estates NaN \n", "22 sethuraman estates NaN \n", "23 our own lab NaN \n", "24 own laboratory NaN \n", "25 cafe cazengo NaN \n", "26 NaN 14-1118-2014-0087 \n", "27 NaN NaN \n", "\n", " Company Altitude ... Color \\\n", "0 ankole coffee producers coop 1488 ... Green \n", "1 kaapi royale 3170 ... NaN \n", "2 sethuraman estate 1000m ... Green \n", "3 ugacof ltd 1212 ... Green \n", "4 katuka development trust ltd 1200-1300 ... Green \n", "5 cafemakers, llc 3000' ... Green \n", "6 cafemakers 750m ... Green \n", "7 kaapi royale 3140 ... Bluish-Green \n", "8 kaapi royale 1000 ... Green \n", "9 ugacof ltd 900-1300 ... Green \n", "10 ugacof ltd 1095 ... Green \n", "11 kaapi royale 1000 ... Green \n", "12 cafemakers 750m ... Green \n", "13 kasozi coffee farmers association 1367 ... Green \n", "14 ankole coffee producers coop 1488 ... Green \n", "15 sethuraman estate 1000m ... Green \n", "16 cafemakers, llc 750m ... Blue-Green \n", "17 kawacom uganda ltd 1600 ... Green \n", "18 nitubaasa ltd 1745 ... Green \n", "19 mannya coffee project 1200 ... Green \n", "20 cafemakers 750m ... Bluish-Green \n", "21 cafemakers, llc 750m ... Green \n", "22 cafemakers, llc 3000' ... Green \n", "23 robustasa NaN ... Blue-Green \n", "24 robustasa 40 ... Blue-Green \n", "25 global opportunity fund 795 meters ... NaN \n", "26 cafe politico NaN ... Green \n", "27 cafe politico NaN ... None \n", "\n", " Category.Two.Defects Expiration \\\n", "0 2 June 26th, 2015 \n", "1 2 October 31st, 2018 \n", "2 0 April 29th, 2016 \n", "3 7 July 14th, 2015 \n", "4 3 June 26th, 2015 \n", "5 0 February 28th, 2013 \n", "6 0 May 15th, 2015 \n", "7 0 October 25th, 2018 \n", "8 0 August 17th, 2017 \n", "9 6 August 5th, 2015 \n", "10 1 June 26th, 2015 \n", "11 0 August 23rd, 2017 \n", "12 1 May 19th, 2015 \n", "13 7 July 14th, 2015 \n", "14 2 July 14th, 2015 \n", "15 0 April 29th, 2016 \n", "16 0 June 3rd, 2014 \n", "17 1 June 27th, 2015 \n", "18 2 June 27th, 2015 \n", "19 1 June 27th, 2015 \n", "20 1 May 19th, 2015 \n", "21 0 June 20th, 2014 \n", "22 0 February 28th, 2013 \n", "23 1 January 18th, 2017 \n", "24 0 January 18th, 2017 \n", "25 6 December 23rd, 2015 \n", "26 1 August 25th, 2015 \n", "27 9 August 25th, 2015 \n", "\n", " Certification.Body \\\n", "0 Uganda Coffee Development Authority \n", "1 Specialty Coffee Association \n", "2 Specialty Coffee Association \n", "3 Uganda Coffee Development Authority \n", "4 Uganda Coffee Development Authority \n", "5 Specialty Coffee Association \n", "6 Specialty Coffee Association \n", "7 Specialty Coffee Association \n", "8 Specialty Coffee Association \n", "9 Uganda Coffee Development Authority \n", "10 Uganda Coffee Development Authority \n", "11 Specialty Coffee Association \n", "12 Specialty Coffee Association \n", "13 Uganda Coffee Development Authority \n", "14 Uganda Coffee Development Authority \n", "15 Specialty Coffee Association \n", "16 Specialty Coffee Association \n", "17 Uganda Coffee Development Authority \n", "18 Uganda Coffee Development Authority \n", "19 Uganda Coffee Development Authority \n", "20 Specialty Coffee Association \n", "21 Specialty Coffee Association \n", "22 Specialty Coffee Association \n", "23 Specialty Coffee Association \n", "24 Specialty Coffee Association \n", "25 Specialty Coffee Association \n", "26 Specialty Coffee Association \n", "27 Specialty Coffee Association \n", "\n", " Certification.Address \\\n", "0 e36d0270932c3b657e96b7b0278dfd85dc0fe743 \n", "1 ff7c18ad303d4b603ac3f8cff7e611ffc735e720 \n", "2 ff7c18ad303d4b603ac3f8cff7e611ffc735e720 \n", "3 e36d0270932c3b657e96b7b0278dfd85dc0fe743 \n", "4 e36d0270932c3b657e96b7b0278dfd85dc0fe743 \n", "5 ff7c18ad303d4b603ac3f8cff7e611ffc735e720 \n", "6 ff7c18ad303d4b603ac3f8cff7e611ffc735e720 \n", "7 ff7c18ad303d4b603ac3f8cff7e611ffc735e720 \n", "8 ff7c18ad303d4b603ac3f8cff7e611ffc735e720 \n", "9 e36d0270932c3b657e96b7b0278dfd85dc0fe743 \n", "10 e36d0270932c3b657e96b7b0278dfd85dc0fe743 \n", "11 ff7c18ad303d4b603ac3f8cff7e611ffc735e720 \n", "12 ff7c18ad303d4b603ac3f8cff7e611ffc735e720 \n", "13 e36d0270932c3b657e96b7b0278dfd85dc0fe743 \n", "14 e36d0270932c3b657e96b7b0278dfd85dc0fe743 \n", "15 ff7c18ad303d4b603ac3f8cff7e611ffc735e720 \n", "16 ff7c18ad303d4b603ac3f8cff7e611ffc735e720 \n", "17 e36d0270932c3b657e96b7b0278dfd85dc0fe743 \n", "18 e36d0270932c3b657e96b7b0278dfd85dc0fe743 \n", "19 e36d0270932c3b657e96b7b0278dfd85dc0fe743 \n", "20 ff7c18ad303d4b603ac3f8cff7e611ffc735e720 \n", "21 ff7c18ad303d4b603ac3f8cff7e611ffc735e720 \n", "22 ff7c18ad303d4b603ac3f8cff7e611ffc735e720 \n", "23 ff7c18ad303d4b603ac3f8cff7e611ffc735e720 \n", "24 ff7c18ad303d4b603ac3f8cff7e611ffc735e720 \n", "25 ff7c18ad303d4b603ac3f8cff7e611ffc735e720 \n", "26 ff7c18ad303d4b603ac3f8cff7e611ffc735e720 \n", "27 ff7c18ad303d4b603ac3f8cff7e611ffc735e720 \n", "\n", " Certification.Contact unit_of_measurement \\\n", "0 03077a1c6bac60e6f514691634a7f6eb5c85aae8 m \n", "1 352d0cf7f3e9be14dad7df644ad65efc27605ae2 m \n", "2 352d0cf7f3e9be14dad7df644ad65efc27605ae2 m \n", "3 03077a1c6bac60e6f514691634a7f6eb5c85aae8 m \n", "4 03077a1c6bac60e6f514691634a7f6eb5c85aae8 m \n", "5 352d0cf7f3e9be14dad7df644ad65efc27605ae2 m \n", "6 352d0cf7f3e9be14dad7df644ad65efc27605ae2 m \n", "7 352d0cf7f3e9be14dad7df644ad65efc27605ae2 m \n", "8 352d0cf7f3e9be14dad7df644ad65efc27605ae2 m \n", "9 03077a1c6bac60e6f514691634a7f6eb5c85aae8 m \n", "10 03077a1c6bac60e6f514691634a7f6eb5c85aae8 m \n", "11 352d0cf7f3e9be14dad7df644ad65efc27605ae2 m \n", "12 352d0cf7f3e9be14dad7df644ad65efc27605ae2 m \n", "13 03077a1c6bac60e6f514691634a7f6eb5c85aae8 m \n", "14 03077a1c6bac60e6f514691634a7f6eb5c85aae8 m \n", "15 352d0cf7f3e9be14dad7df644ad65efc27605ae2 m \n", "16 352d0cf7f3e9be14dad7df644ad65efc27605ae2 m \n", "17 03077a1c6bac60e6f514691634a7f6eb5c85aae8 m \n", "18 03077a1c6bac60e6f514691634a7f6eb5c85aae8 m \n", "19 03077a1c6bac60e6f514691634a7f6eb5c85aae8 m \n", "20 352d0cf7f3e9be14dad7df644ad65efc27605ae2 m \n", "21 352d0cf7f3e9be14dad7df644ad65efc27605ae2 m \n", "22 352d0cf7f3e9be14dad7df644ad65efc27605ae2 m \n", "23 352d0cf7f3e9be14dad7df644ad65efc27605ae2 m \n", "24 352d0cf7f3e9be14dad7df644ad65efc27605ae2 m \n", "25 352d0cf7f3e9be14dad7df644ad65efc27605ae2 m \n", "26 352d0cf7f3e9be14dad7df644ad65efc27605ae2 m \n", "27 352d0cf7f3e9be14dad7df644ad65efc27605ae2 m \n", "\n", " altitude_low_meters altitude_high_meters altitude_mean_meters \n", "0 1488.0 1488.0 1488.0 \n", "1 3170.0 3170.0 3170.0 \n", "2 1000.0 1000.0 1000.0 \n", "3 1212.0 1212.0 1212.0 \n", "4 1200.0 1300.0 1250.0 \n", "5 3000.0 3000.0 3000.0 \n", "6 750.0 750.0 750.0 \n", "7 3140.0 3140.0 3140.0 \n", "8 1000.0 1000.0 1000.0 \n", "9 900.0 1300.0 1100.0 \n", "10 1095.0 1095.0 1095.0 \n", "11 1000.0 1000.0 1000.0 \n", "12 750.0 750.0 750.0 \n", "13 1367.0 1367.0 1367.0 \n", "14 1488.0 1488.0 1488.0 \n", "15 1000.0 1000.0 1000.0 \n", "16 750.0 750.0 750.0 \n", "17 1600.0 1600.0 1600.0 \n", "18 1745.0 1745.0 1745.0 \n", "19 1200.0 1200.0 1200.0 \n", "20 750.0 750.0 750.0 \n", "21 750.0 750.0 750.0 \n", "22 3000.0 3000.0 3000.0 \n", "23 NaN NaN NaN \n", "24 40.0 40.0 40.0 \n", "25 795.0 795.0 795.0 \n", "26 NaN NaN NaN \n", "27 NaN NaN NaN \n", "\n", "[28 rows x 44 columns]" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "coffee_df" ] }, { "cell_type": "code", "execution_count": 5, "id": "0190cf73", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " Unnamed: 0 Species Owner Country.of.Origin \\\n", "0 1 Robusta ankole coffee producers coop Uganda \n", "1 2 Robusta nishant gurjer India \n", "2 3 Robusta andrew hetzel India \n", "3 4 Robusta ugacof Uganda \n", "4 5 Robusta katuka development trust ltd Uganda \n", "5 6 Robusta andrew hetzel India \n", "6 7 Robusta andrew hetzel India \n", "7 8 Robusta nishant gurjer India \n", "8 9 Robusta nishant gurjer India \n", "9 10 Robusta ugacof Uganda \n", "10 11 Robusta ugacof Uganda \n", "11 12 Robusta nishant gurjer India \n", "12 13 Robusta andrew hetzel India \n", "13 14 Robusta kasozi coffee farmers association Uganda \n", "14 15 Robusta ankole coffee producers coop Uganda \n", "15 16 Robusta andrew hetzel India \n", "16 17 Robusta andrew hetzel India \n", "17 18 Robusta kawacom uganda ltd Uganda \n", "18 19 Robusta nitubaasa ltd Uganda \n", "19 20 Robusta mannya coffee project Uganda \n", "20 21 Robusta andrew hetzel India \n", "21 22 Robusta andrew hetzel India \n", "22 23 Robusta andrew hetzel United States \n", "23 24 Robusta luis robles Ecuador \n", "24 25 Robusta luis robles Ecuador \n", "25 26 Robusta james moore United States \n", "26 27 Robusta cafe politico India \n", "27 28 Robusta cafe politico Vietnam \n", "\n", " Farm.Name Lot.Number \\\n", "0 kyangundu cooperative society NaN \n", "1 sethuraman estate kaapi royale 25 \n", "2 sethuraman estate NaN \n", "3 ugacof project area NaN \n", "4 katikamu capca farmers association NaN \n", "5 NaN NaN \n", "6 sethuraman estates NaN \n", "7 sethuraman estate kaapi royale 7 \n", "8 sethuraman estate RKR \n", "9 ishaka NaN \n", "10 ugacof project area NaN \n", "11 sethuraman estate kaapi royale RC AB \n", "12 sethuraman estates NaN \n", "13 kasozi coffee farmers NaN \n", "14 kyangundu coop society NaN \n", "15 sethuraman estate NaN \n", "16 sethuraman estates NaN \n", "17 bushenyi NaN \n", "18 kigezi coffee farmers association NaN \n", "19 mannya coffee project NaN \n", "20 sethuraman estates NaN \n", "21 sethuraman estates NaN \n", "22 sethuraman estates NaN \n", "23 robustasa Lavado 1 \n", "24 robustasa Lavado 3 \n", "25 fazenda cazengo NaN \n", "26 NaN NaN \n", "27 NaN NaN \n", "\n", " Mill ICO.Number \\\n", "0 ankole coffee producers 0 \n", "1 sethuraman estate 14/1148/2017/21 \n", "2 NaN 0000 \n", "3 ugacof 0 \n", "4 katuka development trust 0 \n", "5 (self) NaN \n", "6 NaN NaN \n", "7 sethuraman estate 14/1148/2017/18 \n", "8 sethuraman estate 14/1148/2016/17 \n", "9 nsubuga umar 0 \n", "10 ugacof 0 \n", "11 sethuraman estate 14/1148/2016/12 \n", "12 NaN NaN \n", "13 NaN 0 \n", "14 ankole coffee producers coop union ltd 0 \n", "15 NaN 0000 \n", "16 sethuraman estates NaN \n", "17 kawacom 0 \n", "18 nitubaasa 0 \n", "19 mannya coffee project 0 \n", "20 NaN NaN \n", "21 sethuraman estates NaN \n", "22 sethuraman estates NaN \n", "23 our own lab NaN \n", "24 own laboratory NaN \n", "25 cafe cazengo NaN \n", "26 NaN 14-1118-2014-0087 \n", "27 NaN NaN \n", "\n", " Company Altitude ... Color \\\n", "0 ankole coffee producers coop 1488 ... Green \n", "1 kaapi royale 3170 ... NaN \n", "2 sethuraman estate 1000m ... Green \n", "3 ugacof ltd 1212 ... Green \n", "4 katuka development trust ltd 1200-1300 ... Green \n", "5 cafemakers, llc 3000' ... Green \n", "6 cafemakers 750m ... Green \n", "7 kaapi royale 3140 ... Bluish-Green \n", "8 kaapi royale 1000 ... Green \n", "9 ugacof ltd 900-1300 ... Green \n", "10 ugacof ltd 1095 ... Green \n", "11 kaapi royale 1000 ... Green \n", "12 cafemakers 750m ... Green \n", "13 kasozi coffee farmers association 1367 ... Green \n", "14 ankole coffee producers coop 1488 ... Green \n", "15 sethuraman estate 1000m ... Green \n", "16 cafemakers, llc 750m ... Blue-Green \n", "17 kawacom uganda ltd 1600 ... Green \n", "18 nitubaasa ltd 1745 ... Green \n", "19 mannya coffee project 1200 ... Green \n", "20 cafemakers 750m ... Bluish-Green \n", "21 cafemakers, llc 750m ... Green \n", "22 cafemakers, llc 3000' ... Green \n", "23 robustasa NaN ... Blue-Green \n", "24 robustasa 40 ... Blue-Green \n", "25 global opportunity fund 795 meters ... NaN \n", "26 cafe politico NaN ... Green \n", "27 cafe politico NaN ... None \n", "\n", " Category.Two.Defects Expiration \\\n", "0 2 June 26th, 2015 \n", "1 2 October 31st, 2018 \n", "2 0 April 29th, 2016 \n", "3 7 July 14th, 2015 \n", "4 3 June 26th, 2015 \n", "5 0 February 28th, 2013 \n", "6 0 May 15th, 2015 \n", "7 0 October 25th, 2018 \n", "8 0 August 17th, 2017 \n", "9 6 August 5th, 2015 \n", "10 1 June 26th, 2015 \n", "11 0 August 23rd, 2017 \n", "12 1 May 19th, 2015 \n", "13 7 July 14th, 2015 \n", "14 2 July 14th, 2015 \n", "15 0 April 29th, 2016 \n", "16 0 June 3rd, 2014 \n", "17 1 June 27th, 2015 \n", "18 2 June 27th, 2015 \n", "19 1 June 27th, 2015 \n", "20 1 May 19th, 2015 \n", "21 0 June 20th, 2014 \n", "22 0 February 28th, 2013 \n", "23 1 January 18th, 2017 \n", "24 0 January 18th, 2017 \n", "25 6 December 23rd, 2015 \n", "26 1 August 25th, 2015 \n", "27 9 August 25th, 2015 \n", "\n", " Certification.Body \\\n", "0 Uganda Coffee Development Authority \n", "1 Specialty Coffee Association \n", "2 Specialty Coffee Association \n", "3 Uganda Coffee Development Authority \n", "4 Uganda Coffee Development Authority \n", "5 Specialty Coffee Association \n", "6 Specialty Coffee Association \n", "7 Specialty Coffee Association \n", "8 Specialty Coffee Association \n", "9 Uganda Coffee Development Authority \n", "10 Uganda Coffee Development Authority \n", "11 Specialty Coffee Association \n", "12 Specialty Coffee Association \n", "13 Uganda Coffee Development Authority \n", "14 Uganda Coffee Development Authority \n", "15 Specialty Coffee Association \n", "16 Specialty Coffee Association \n", "17 Uganda Coffee Development Authority \n", "18 Uganda Coffee Development Authority \n", "19 Uganda Coffee Development Authority \n", "20 Specialty Coffee Association \n", "21 Specialty Coffee Association \n", "22 Specialty Coffee Association \n", "23 Specialty Coffee Association \n", "24 Specialty Coffee Association \n", "25 Specialty Coffee Association \n", "26 Specialty Coffee Association \n", "27 Specialty Coffee Association \n", "\n", " Certification.Address \\\n", "0 e36d0270932c3b657e96b7b0278dfd85dc0fe743 \n", "1 ff7c18ad303d4b603ac3f8cff7e611ffc735e720 \n", "2 ff7c18ad303d4b603ac3f8cff7e611ffc735e720 \n", "3 e36d0270932c3b657e96b7b0278dfd85dc0fe743 \n", "4 e36d0270932c3b657e96b7b0278dfd85dc0fe743 \n", "5 ff7c18ad303d4b603ac3f8cff7e611ffc735e720 \n", "6 ff7c18ad303d4b603ac3f8cff7e611ffc735e720 \n", "7 ff7c18ad303d4b603ac3f8cff7e611ffc735e720 \n", "8 ff7c18ad303d4b603ac3f8cff7e611ffc735e720 \n", "9 e36d0270932c3b657e96b7b0278dfd85dc0fe743 \n", "10 e36d0270932c3b657e96b7b0278dfd85dc0fe743 \n", "11 ff7c18ad303d4b603ac3f8cff7e611ffc735e720 \n", "12 ff7c18ad303d4b603ac3f8cff7e611ffc735e720 \n", "13 e36d0270932c3b657e96b7b0278dfd85dc0fe743 \n", "14 e36d0270932c3b657e96b7b0278dfd85dc0fe743 \n", "15 ff7c18ad303d4b603ac3f8cff7e611ffc735e720 \n", "16 ff7c18ad303d4b603ac3f8cff7e611ffc735e720 \n", "17 e36d0270932c3b657e96b7b0278dfd85dc0fe743 \n", "18 e36d0270932c3b657e96b7b0278dfd85dc0fe743 \n", "19 e36d0270932c3b657e96b7b0278dfd85dc0fe743 \n", "20 ff7c18ad303d4b603ac3f8cff7e611ffc735e720 \n", "21 ff7c18ad303d4b603ac3f8cff7e611ffc735e720 \n", "22 ff7c18ad303d4b603ac3f8cff7e611ffc735e720 \n", "23 ff7c18ad303d4b603ac3f8cff7e611ffc735e720 \n", "24 ff7c18ad303d4b603ac3f8cff7e611ffc735e720 \n", "25 ff7c18ad303d4b603ac3f8cff7e611ffc735e720 \n", "26 ff7c18ad303d4b603ac3f8cff7e611ffc735e720 \n", "27 ff7c18ad303d4b603ac3f8cff7e611ffc735e720 \n", "\n", " Certification.Contact unit_of_measurement \\\n", "0 03077a1c6bac60e6f514691634a7f6eb5c85aae8 m \n", "1 352d0cf7f3e9be14dad7df644ad65efc27605ae2 m \n", "2 352d0cf7f3e9be14dad7df644ad65efc27605ae2 m \n", "3 03077a1c6bac60e6f514691634a7f6eb5c85aae8 m \n", "4 03077a1c6bac60e6f514691634a7f6eb5c85aae8 m \n", "5 352d0cf7f3e9be14dad7df644ad65efc27605ae2 m \n", "6 352d0cf7f3e9be14dad7df644ad65efc27605ae2 m \n", "7 352d0cf7f3e9be14dad7df644ad65efc27605ae2 m \n", "8 352d0cf7f3e9be14dad7df644ad65efc27605ae2 m \n", "9 03077a1c6bac60e6f514691634a7f6eb5c85aae8 m \n", "10 03077a1c6bac60e6f514691634a7f6eb5c85aae8 m \n", "11 352d0cf7f3e9be14dad7df644ad65efc27605ae2 m \n", "12 352d0cf7f3e9be14dad7df644ad65efc27605ae2 m \n", "13 03077a1c6bac60e6f514691634a7f6eb5c85aae8 m \n", "14 03077a1c6bac60e6f514691634a7f6eb5c85aae8 m \n", "15 352d0cf7f3e9be14dad7df644ad65efc27605ae2 m \n", "16 352d0cf7f3e9be14dad7df644ad65efc27605ae2 m \n", "17 03077a1c6bac60e6f514691634a7f6eb5c85aae8 m \n", "18 03077a1c6bac60e6f514691634a7f6eb5c85aae8 m \n", "19 03077a1c6bac60e6f514691634a7f6eb5c85aae8 m \n", "20 352d0cf7f3e9be14dad7df644ad65efc27605ae2 m \n", "21 352d0cf7f3e9be14dad7df644ad65efc27605ae2 m \n", "22 352d0cf7f3e9be14dad7df644ad65efc27605ae2 m \n", "23 352d0cf7f3e9be14dad7df644ad65efc27605ae2 m \n", "24 352d0cf7f3e9be14dad7df644ad65efc27605ae2 m \n", "25 352d0cf7f3e9be14dad7df644ad65efc27605ae2 m \n", "26 352d0cf7f3e9be14dad7df644ad65efc27605ae2 m \n", "27 352d0cf7f3e9be14dad7df644ad65efc27605ae2 m \n", "\n", " altitude_low_meters altitude_high_meters altitude_mean_meters \n", "0 1488.0 1488.0 1488.0 \n", "1 3170.0 3170.0 3170.0 \n", "2 1000.0 1000.0 1000.0 \n", "3 1212.0 1212.0 1212.0 \n", "4 1200.0 1300.0 1250.0 \n", "5 3000.0 3000.0 3000.0 \n", "6 750.0 750.0 750.0 \n", "7 3140.0 3140.0 3140.0 \n", "8 1000.0 1000.0 1000.0 \n", "9 900.0 1300.0 1100.0 \n", "10 1095.0 1095.0 1095.0 \n", "11 1000.0 1000.0 1000.0 \n", "12 750.0 750.0 750.0 \n", "13 1367.0 1367.0 1367.0 \n", "14 1488.0 1488.0 1488.0 \n", "15 1000.0 1000.0 1000.0 \n", "16 750.0 750.0 750.0 \n", "17 1600.0 1600.0 1600.0 \n", "18 1745.0 1745.0 1745.0 \n", "19 1200.0 1200.0 1200.0 \n", "20 750.0 750.0 750.0 \n", "21 750.0 750.0 750.0 \n", "22 3000.0 3000.0 3000.0 \n", "23 NaN NaN NaN \n", "24 40.0 40.0 40.0 \n", "25 795.0 795.0 795.0 \n", "26 NaN NaN NaN \n", "27 NaN NaN NaN \n", "\n", "[28 rows x 44 columns]\n" ] } ], "source": [ "print(coffee_df)" ] }, { "cell_type": "markdown", "id": "77ab762e", "metadata": {}, "source": [ "## Examining the Structure of a Data Frame\n", "\n", "I told you this was a DataFrame, but we can check with type." ] }, { "cell_type": "code", "execution_count": 6, "id": "9e01d018", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "pandas.core.frame.DataFrame" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "type(coffee_df)" ] }, { "cell_type": "markdown", "id": "7741133d", "metadata": {}, "source": [ "We can also see that the DataFrame type comes from the `pandas` library, without the library loaded this type does not exist.\n", "\n", "\n", "We can also exmaine its parts. It consists of several; first the column headings" ] }, { "cell_type": "code", "execution_count": 7, "id": "7afeb8c8", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Index(['Unnamed: 0', 'Species', 'Owner', 'Country.of.Origin', 'Farm.Name',\n", " 'Lot.Number', 'Mill', 'ICO.Number', 'Company', 'Altitude', 'Region',\n", " 'Producer', 'Number.of.Bags', 'Bag.Weight', 'In.Country.Partner',\n", " 'Harvest.Year', 'Grading.Date', 'Owner.1', 'Variety',\n", " 'Processing.Method', 'Fragrance...Aroma', 'Flavor', 'Aftertaste',\n", " 'Salt...Acid', 'Bitter...Sweet', 'Mouthfeel', 'Uniform.Cup',\n", " 'Clean.Cup', 'Balance', 'Cupper.Points', 'Total.Cup.Points', 'Moisture',\n", " 'Category.One.Defects', 'Quakers', 'Color', 'Category.Two.Defects',\n", " 'Expiration', 'Certification.Body', 'Certification.Address',\n", " 'Certification.Contact', 'unit_of_measurement', 'altitude_low_meters',\n", " 'altitude_high_meters', 'altitude_mean_meters'],\n", " dtype='object')" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "coffee_df.columns" ] }, { "cell_type": "markdown", "id": "6507c5bb", "metadata": {}, "source": [ "These are a special type called Index" ] }, { "cell_type": "code", "execution_count": 8, "id": "cddad728", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "pandas.core.indexes.base.Index" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "type(coffee_df.columns)" ] }, { "cell_type": "markdown", "id": "a5fb044d", "metadata": {}, "source": [ "These are still iterable, much like python lists.\n", "\n", "\n", "and it stores the data" ] }, { "cell_type": "code", "execution_count": 9, "id": "6922ac2a", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([[1, 'Robusta', 'ankole coffee producers coop', ..., 1488.0,\n", " 1488.0, 1488.0],\n", " [2, 'Robusta', 'nishant gurjer', ..., 3170.0, 3170.0, 3170.0],\n", " [3, 'Robusta', 'andrew hetzel', ..., 1000.0, 1000.0, 1000.0],\n", " ...,\n", " [26, 'Robusta', 'james moore', ..., 795.0, 795.0, 795.0],\n", " [27, 'Robusta', 'cafe politico', ..., nan, nan, nan],\n", " [28, 'Robusta', 'cafe politico', ..., nan, nan, nan]], dtype=object)" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "coffee_df.values" ] }, { "cell_type": "markdown", "id": "3ad2c9a9", "metadata": {}, "source": [ "It also has an index (first column, visually) but it is special because this is how you can index the data." ] }, { "cell_type": "code", "execution_count": 10, "id": "595be0dd", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "RangeIndex(start=0, stop=28, step=1)" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "coffee_df.index" ] }, { "cell_type": "markdown", "id": "4b0465cf", "metadata": {}, "source": [ "Right now this is an autogenerated index, but we can also use the `index_col` parameter to set that up front." ] }, { "cell_type": "code", "execution_count": 11, "id": "c0d72646", "metadata": {}, "outputs": [ { "data": { "text/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", " \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", " \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", " \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", " \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", " \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", " \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", " \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", " \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", " \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", " \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", " \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", " \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", " \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", " \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", " \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", " \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", "
SpeciesOwnerCountry.of.OriginFarm.NameLot.NumberMillICO.NumberCompanyAltitudeRegion...ColorCategory.Two.DefectsExpirationCertification.BodyCertification.AddressCertification.Contactunit_of_measurementaltitude_low_metersaltitude_high_metersaltitude_mean_meters
1Robustaankole coffee producers coopUgandakyangundu cooperative societyNaNankole coffee producers0ankole coffee producers coop1488sheema south western...Green2June 26th, 2015Uganda Coffee Development Authoritye36d0270932c3b657e96b7b0278dfd85dc0fe74303077a1c6bac60e6f514691634a7f6eb5c85aae8m1488.01488.01488.0
2Robustanishant gurjerIndiasethuraman estate kaapi royale25sethuraman estate14/1148/2017/21kaapi royale3170chikmagalur karnataka indua...NaN2October 31st, 2018Specialty Coffee Associationff7c18ad303d4b603ac3f8cff7e611ffc735e720352d0cf7f3e9be14dad7df644ad65efc27605ae2m3170.03170.03170.0
3Robustaandrew hetzelIndiasethuraman estateNaNNaN0000sethuraman estate1000mchikmagalur...Green0April 29th, 2016Specialty Coffee Associationff7c18ad303d4b603ac3f8cff7e611ffc735e720352d0cf7f3e9be14dad7df644ad65efc27605ae2m1000.01000.01000.0
4RobustaugacofUgandaugacof project areaNaNugacof0ugacof ltd1212central...Green7July 14th, 2015Uganda Coffee Development Authoritye36d0270932c3b657e96b7b0278dfd85dc0fe74303077a1c6bac60e6f514691634a7f6eb5c85aae8m1212.01212.01212.0
5Robustakatuka development trust ltdUgandakatikamu capca farmers associationNaNkatuka development trust0katuka development trust ltd1200-1300luwero central region...Green3June 26th, 2015Uganda Coffee Development Authoritye36d0270932c3b657e96b7b0278dfd85dc0fe74303077a1c6bac60e6f514691634a7f6eb5c85aae8m1200.01300.01250.0
6Robustaandrew hetzelIndiaNaNNaN(self)NaNcafemakers, llc3000'chikmagalur...Green0February 28th, 2013Specialty Coffee Associationff7c18ad303d4b603ac3f8cff7e611ffc735e720352d0cf7f3e9be14dad7df644ad65efc27605ae2m3000.03000.03000.0
7Robustaandrew hetzelIndiasethuraman estatesNaNNaNNaNcafemakers750mchikmagalur...Green0May 15th, 2015Specialty Coffee Associationff7c18ad303d4b603ac3f8cff7e611ffc735e720352d0cf7f3e9be14dad7df644ad65efc27605ae2m750.0750.0750.0
8Robustanishant gurjerIndiasethuraman estate kaapi royale7sethuraman estate14/1148/2017/18kaapi royale3140chikmagalur karnataka india...Bluish-Green0October 25th, 2018Specialty Coffee Associationff7c18ad303d4b603ac3f8cff7e611ffc735e720352d0cf7f3e9be14dad7df644ad65efc27605ae2m3140.03140.03140.0
9Robustanishant gurjerIndiasethuraman estateRKRsethuraman estate14/1148/2016/17kaapi royale1000chikmagalur karnataka...Green0August 17th, 2017Specialty Coffee Associationff7c18ad303d4b603ac3f8cff7e611ffc735e720352d0cf7f3e9be14dad7df644ad65efc27605ae2m1000.01000.01000.0
10RobustaugacofUgandaishakaNaNnsubuga umar0ugacof ltd900-1300western...Green6August 5th, 2015Uganda Coffee Development Authoritye36d0270932c3b657e96b7b0278dfd85dc0fe74303077a1c6bac60e6f514691634a7f6eb5c85aae8m900.01300.01100.0
11RobustaugacofUgandaugacof project areaNaNugacof0ugacof ltd1095iganga namadrope eastern...Green1June 26th, 2015Uganda Coffee Development Authoritye36d0270932c3b657e96b7b0278dfd85dc0fe74303077a1c6bac60e6f514691634a7f6eb5c85aae8m1095.01095.01095.0
12Robustanishant gurjerIndiasethuraman estate kaapi royaleRC ABsethuraman estate14/1148/2016/12kaapi royale1000chikmagalur karnataka...Green0August 23rd, 2017Specialty Coffee Associationff7c18ad303d4b603ac3f8cff7e611ffc735e720352d0cf7f3e9be14dad7df644ad65efc27605ae2m1000.01000.01000.0
13Robustaandrew hetzelIndiasethuraman estatesNaNNaNNaNcafemakers750mchikmagalur...Green1May 19th, 2015Specialty Coffee Associationff7c18ad303d4b603ac3f8cff7e611ffc735e720352d0cf7f3e9be14dad7df644ad65efc27605ae2m750.0750.0750.0
14Robustakasozi coffee farmers associationUgandakasozi coffee farmersNaNNaN0kasozi coffee farmers association1367eastern...Green7July 14th, 2015Uganda Coffee Development Authoritye36d0270932c3b657e96b7b0278dfd85dc0fe74303077a1c6bac60e6f514691634a7f6eb5c85aae8m1367.01367.01367.0
15Robustaankole coffee producers coopUgandakyangundu coop societyNaNankole coffee producers coop union ltd0ankole coffee producers coop1488south western...Green2July 14th, 2015Uganda Coffee Development Authoritye36d0270932c3b657e96b7b0278dfd85dc0fe74303077a1c6bac60e6f514691634a7f6eb5c85aae8m1488.01488.01488.0
16Robustaandrew hetzelIndiasethuraman estateNaNNaN0000sethuraman estate1000mchikmagalur...Green0April 29th, 2016Specialty Coffee Associationff7c18ad303d4b603ac3f8cff7e611ffc735e720352d0cf7f3e9be14dad7df644ad65efc27605ae2m1000.01000.01000.0
17Robustaandrew hetzelIndiasethuraman estatesNaNsethuraman estatesNaNcafemakers, llc750mchikmagalur...Blue-Green0June 3rd, 2014Specialty Coffee Associationff7c18ad303d4b603ac3f8cff7e611ffc735e720352d0cf7f3e9be14dad7df644ad65efc27605ae2m750.0750.0750.0
18Robustakawacom uganda ltdUgandabushenyiNaNkawacom0kawacom uganda ltd1600western...Green1June 27th, 2015Uganda Coffee Development Authoritye36d0270932c3b657e96b7b0278dfd85dc0fe74303077a1c6bac60e6f514691634a7f6eb5c85aae8m1600.01600.01600.0
19Robustanitubaasa ltdUgandakigezi coffee farmers associationNaNnitubaasa0nitubaasa ltd1745western...Green2June 27th, 2015Uganda Coffee Development Authoritye36d0270932c3b657e96b7b0278dfd85dc0fe74303077a1c6bac60e6f514691634a7f6eb5c85aae8m1745.01745.01745.0
20Robustamannya coffee projectUgandamannya coffee projectNaNmannya coffee project0mannya coffee project1200southern...Green1June 27th, 2015Uganda Coffee Development Authoritye36d0270932c3b657e96b7b0278dfd85dc0fe74303077a1c6bac60e6f514691634a7f6eb5c85aae8m1200.01200.01200.0
21Robustaandrew hetzelIndiasethuraman estatesNaNNaNNaNcafemakers750mchikmagalur...Bluish-Green1May 19th, 2015Specialty Coffee Associationff7c18ad303d4b603ac3f8cff7e611ffc735e720352d0cf7f3e9be14dad7df644ad65efc27605ae2m750.0750.0750.0
22Robustaandrew hetzelIndiasethuraman estatesNaNsethuraman estatesNaNcafemakers, llc750mchikmagalur...Green0June 20th, 2014Specialty Coffee Associationff7c18ad303d4b603ac3f8cff7e611ffc735e720352d0cf7f3e9be14dad7df644ad65efc27605ae2m750.0750.0750.0
23Robustaandrew hetzelUnited Statessethuraman estatesNaNsethuraman estatesNaNcafemakers, llc3000'chikmagalur...Green0February 28th, 2013Specialty Coffee Associationff7c18ad303d4b603ac3f8cff7e611ffc735e720352d0cf7f3e9be14dad7df644ad65efc27605ae2m3000.03000.03000.0
24Robustaluis roblesEcuadorrobustasaLavado 1our own labNaNrobustasaNaNsan juan, playas...Blue-Green1January 18th, 2017Specialty Coffee Associationff7c18ad303d4b603ac3f8cff7e611ffc735e720352d0cf7f3e9be14dad7df644ad65efc27605ae2mNaNNaNNaN
25Robustaluis roblesEcuadorrobustasaLavado 3own laboratoryNaNrobustasa40san juan, playas...Blue-Green0January 18th, 2017Specialty Coffee Associationff7c18ad303d4b603ac3f8cff7e611ffc735e720352d0cf7f3e9be14dad7df644ad65efc27605ae2m40.040.040.0
26Robustajames mooreUnited Statesfazenda cazengoNaNcafe cazengoNaNglobal opportunity fund795 meterskwanza norte province, angola...NaN6December 23rd, 2015Specialty Coffee Associationff7c18ad303d4b603ac3f8cff7e611ffc735e720352d0cf7f3e9be14dad7df644ad65efc27605ae2m795.0795.0795.0
27Robustacafe politicoIndiaNaNNaNNaN14-1118-2014-0087cafe politicoNaNNaN...Green1August 25th, 2015Specialty Coffee Associationff7c18ad303d4b603ac3f8cff7e611ffc735e720352d0cf7f3e9be14dad7df644ad65efc27605ae2mNaNNaNNaN
28Robustacafe politicoVietnamNaNNaNNaNNaNcafe politicoNaNNaN...None9August 25th, 2015Specialty Coffee Associationff7c18ad303d4b603ac3f8cff7e611ffc735e720352d0cf7f3e9be14dad7df644ad65efc27605ae2mNaNNaNNaN
\n", "

28 rows × 43 columns

\n", "
" ], "text/plain": [ " Species Owner Country.of.Origin \\\n", "1 Robusta ankole coffee producers coop Uganda \n", "2 Robusta nishant gurjer India \n", "3 Robusta andrew hetzel India \n", "4 Robusta ugacof Uganda \n", "5 Robusta katuka development trust ltd Uganda \n", "6 Robusta andrew hetzel India \n", "7 Robusta andrew hetzel India \n", "8 Robusta nishant gurjer India \n", "9 Robusta nishant gurjer India \n", "10 Robusta ugacof Uganda \n", "11 Robusta ugacof Uganda \n", "12 Robusta nishant gurjer India \n", "13 Robusta andrew hetzel India \n", "14 Robusta kasozi coffee farmers association Uganda \n", "15 Robusta ankole coffee producers coop Uganda \n", "16 Robusta andrew hetzel India \n", "17 Robusta andrew hetzel India \n", "18 Robusta kawacom uganda ltd Uganda \n", "19 Robusta nitubaasa ltd Uganda \n", "20 Robusta mannya coffee project Uganda \n", "21 Robusta andrew hetzel India \n", "22 Robusta andrew hetzel India \n", "23 Robusta andrew hetzel United States \n", "24 Robusta luis robles Ecuador \n", "25 Robusta luis robles Ecuador \n", "26 Robusta james moore United States \n", "27 Robusta cafe politico India \n", "28 Robusta cafe politico Vietnam \n", "\n", " Farm.Name Lot.Number \\\n", "1 kyangundu cooperative society NaN \n", "2 sethuraman estate kaapi royale 25 \n", "3 sethuraman estate NaN \n", "4 ugacof project area NaN \n", "5 katikamu capca farmers association NaN \n", "6 NaN NaN \n", "7 sethuraman estates NaN \n", "8 sethuraman estate kaapi royale 7 \n", "9 sethuraman estate RKR \n", "10 ishaka NaN \n", "11 ugacof project area NaN \n", "12 sethuraman estate kaapi royale RC AB \n", "13 sethuraman estates NaN \n", "14 kasozi coffee farmers NaN \n", "15 kyangundu coop society NaN \n", "16 sethuraman estate NaN \n", "17 sethuraman estates NaN \n", "18 bushenyi NaN \n", "19 kigezi coffee farmers association NaN \n", "20 mannya coffee project NaN \n", "21 sethuraman estates NaN \n", "22 sethuraman estates NaN \n", "23 sethuraman estates NaN \n", "24 robustasa Lavado 1 \n", "25 robustasa Lavado 3 \n", "26 fazenda cazengo NaN \n", "27 NaN NaN \n", "28 NaN NaN \n", "\n", " Mill ICO.Number \\\n", "1 ankole coffee producers 0 \n", "2 sethuraman estate 14/1148/2017/21 \n", "3 NaN 0000 \n", "4 ugacof 0 \n", "5 katuka development trust 0 \n", "6 (self) NaN \n", "7 NaN NaN \n", "8 sethuraman estate 14/1148/2017/18 \n", "9 sethuraman estate 14/1148/2016/17 \n", "10 nsubuga umar 0 \n", "11 ugacof 0 \n", "12 sethuraman estate 14/1148/2016/12 \n", "13 NaN NaN \n", "14 NaN 0 \n", "15 ankole coffee producers coop union ltd 0 \n", "16 NaN 0000 \n", "17 sethuraman estates NaN \n", "18 kawacom 0 \n", "19 nitubaasa 0 \n", "20 mannya coffee project 0 \n", "21 NaN NaN \n", "22 sethuraman estates NaN \n", "23 sethuraman estates NaN \n", "24 our own lab NaN \n", "25 own laboratory NaN \n", "26 cafe cazengo NaN \n", "27 NaN 14-1118-2014-0087 \n", "28 NaN NaN \n", "\n", " Company Altitude \\\n", "1 ankole coffee producers coop 1488 \n", "2 kaapi royale 3170 \n", "3 sethuraman estate 1000m \n", "4 ugacof ltd 1212 \n", "5 katuka development trust ltd 1200-1300 \n", "6 cafemakers, llc 3000' \n", "7 cafemakers 750m \n", "8 kaapi royale 3140 \n", "9 kaapi royale 1000 \n", "10 ugacof ltd 900-1300 \n", "11 ugacof ltd 1095 \n", "12 kaapi royale 1000 \n", "13 cafemakers 750m \n", "14 kasozi coffee farmers association 1367 \n", "15 ankole coffee producers coop 1488 \n", "16 sethuraman estate 1000m \n", "17 cafemakers, llc 750m \n", "18 kawacom uganda ltd 1600 \n", "19 nitubaasa ltd 1745 \n", "20 mannya coffee project 1200 \n", "21 cafemakers 750m \n", "22 cafemakers, llc 750m \n", "23 cafemakers, llc 3000' \n", "24 robustasa NaN \n", "25 robustasa 40 \n", "26 global opportunity fund 795 meters \n", "27 cafe politico NaN \n", "28 cafe politico NaN \n", "\n", " Region ... Color Category.Two.Defects \\\n", "1 sheema south western ... Green 2 \n", "2 chikmagalur karnataka indua ... NaN 2 \n", "3 chikmagalur ... Green 0 \n", "4 central ... Green 7 \n", "5 luwero central region ... Green 3 \n", "6 chikmagalur ... Green 0 \n", "7 chikmagalur ... Green 0 \n", "8 chikmagalur karnataka india ... Bluish-Green 0 \n", "9 chikmagalur karnataka ... Green 0 \n", "10 western ... Green 6 \n", "11 iganga namadrope eastern ... Green 1 \n", "12 chikmagalur karnataka ... Green 0 \n", "13 chikmagalur ... Green 1 \n", "14 eastern ... Green 7 \n", "15 south western ... Green 2 \n", "16 chikmagalur ... Green 0 \n", "17 chikmagalur ... Blue-Green 0 \n", "18 western ... Green 1 \n", "19 western ... Green 2 \n", "20 southern ... Green 1 \n", "21 chikmagalur ... Bluish-Green 1 \n", "22 chikmagalur ... Green 0 \n", "23 chikmagalur ... Green 0 \n", "24 san juan, playas ... Blue-Green 1 \n", "25 san juan, playas ... Blue-Green 0 \n", "26 kwanza norte province, angola ... NaN 6 \n", "27 NaN ... Green 1 \n", "28 NaN ... None 9 \n", "\n", " Expiration Certification.Body \\\n", "1 June 26th, 2015 Uganda Coffee Development Authority \n", "2 October 31st, 2018 Specialty Coffee Association \n", "3 April 29th, 2016 Specialty Coffee Association \n", "4 July 14th, 2015 Uganda Coffee Development Authority \n", "5 June 26th, 2015 Uganda Coffee Development Authority \n", "6 February 28th, 2013 Specialty Coffee Association \n", "7 May 15th, 2015 Specialty Coffee Association \n", "8 October 25th, 2018 Specialty Coffee Association \n", "9 August 17th, 2017 Specialty Coffee Association \n", "10 August 5th, 2015 Uganda Coffee Development Authority \n", "11 June 26th, 2015 Uganda Coffee Development Authority \n", "12 August 23rd, 2017 Specialty Coffee Association \n", "13 May 19th, 2015 Specialty Coffee Association \n", "14 July 14th, 2015 Uganda Coffee Development Authority \n", "15 July 14th, 2015 Uganda Coffee Development Authority \n", "16 April 29th, 2016 Specialty Coffee Association \n", "17 June 3rd, 2014 Specialty Coffee Association \n", "18 June 27th, 2015 Uganda Coffee Development Authority \n", "19 June 27th, 2015 Uganda Coffee Development Authority \n", "20 June 27th, 2015 Uganda Coffee Development Authority \n", "21 May 19th, 2015 Specialty Coffee Association \n", "22 June 20th, 2014 Specialty Coffee Association \n", "23 February 28th, 2013 Specialty Coffee Association \n", "24 January 18th, 2017 Specialty Coffee Association \n", "25 January 18th, 2017 Specialty Coffee Association \n", "26 December 23rd, 2015 Specialty Coffee Association \n", "27 August 25th, 2015 Specialty Coffee Association \n", "28 August 25th, 2015 Specialty Coffee Association \n", "\n", " Certification.Address \\\n", "1 e36d0270932c3b657e96b7b0278dfd85dc0fe743 \n", "2 ff7c18ad303d4b603ac3f8cff7e611ffc735e720 \n", "3 ff7c18ad303d4b603ac3f8cff7e611ffc735e720 \n", "4 e36d0270932c3b657e96b7b0278dfd85dc0fe743 \n", "5 e36d0270932c3b657e96b7b0278dfd85dc0fe743 \n", "6 ff7c18ad303d4b603ac3f8cff7e611ffc735e720 \n", "7 ff7c18ad303d4b603ac3f8cff7e611ffc735e720 \n", "8 ff7c18ad303d4b603ac3f8cff7e611ffc735e720 \n", "9 ff7c18ad303d4b603ac3f8cff7e611ffc735e720 \n", "10 e36d0270932c3b657e96b7b0278dfd85dc0fe743 \n", "11 e36d0270932c3b657e96b7b0278dfd85dc0fe743 \n", "12 ff7c18ad303d4b603ac3f8cff7e611ffc735e720 \n", "13 ff7c18ad303d4b603ac3f8cff7e611ffc735e720 \n", "14 e36d0270932c3b657e96b7b0278dfd85dc0fe743 \n", "15 e36d0270932c3b657e96b7b0278dfd85dc0fe743 \n", "16 ff7c18ad303d4b603ac3f8cff7e611ffc735e720 \n", "17 ff7c18ad303d4b603ac3f8cff7e611ffc735e720 \n", "18 e36d0270932c3b657e96b7b0278dfd85dc0fe743 \n", "19 e36d0270932c3b657e96b7b0278dfd85dc0fe743 \n", "20 e36d0270932c3b657e96b7b0278dfd85dc0fe743 \n", "21 ff7c18ad303d4b603ac3f8cff7e611ffc735e720 \n", "22 ff7c18ad303d4b603ac3f8cff7e611ffc735e720 \n", "23 ff7c18ad303d4b603ac3f8cff7e611ffc735e720 \n", "24 ff7c18ad303d4b603ac3f8cff7e611ffc735e720 \n", "25 ff7c18ad303d4b603ac3f8cff7e611ffc735e720 \n", "26 ff7c18ad303d4b603ac3f8cff7e611ffc735e720 \n", "27 ff7c18ad303d4b603ac3f8cff7e611ffc735e720 \n", "28 ff7c18ad303d4b603ac3f8cff7e611ffc735e720 \n", "\n", " Certification.Contact unit_of_measurement \\\n", "1 03077a1c6bac60e6f514691634a7f6eb5c85aae8 m \n", "2 352d0cf7f3e9be14dad7df644ad65efc27605ae2 m \n", "3 352d0cf7f3e9be14dad7df644ad65efc27605ae2 m \n", "4 03077a1c6bac60e6f514691634a7f6eb5c85aae8 m \n", "5 03077a1c6bac60e6f514691634a7f6eb5c85aae8 m \n", "6 352d0cf7f3e9be14dad7df644ad65efc27605ae2 m \n", "7 352d0cf7f3e9be14dad7df644ad65efc27605ae2 m \n", "8 352d0cf7f3e9be14dad7df644ad65efc27605ae2 m \n", "9 352d0cf7f3e9be14dad7df644ad65efc27605ae2 m \n", "10 03077a1c6bac60e6f514691634a7f6eb5c85aae8 m \n", "11 03077a1c6bac60e6f514691634a7f6eb5c85aae8 m \n", "12 352d0cf7f3e9be14dad7df644ad65efc27605ae2 m \n", "13 352d0cf7f3e9be14dad7df644ad65efc27605ae2 m \n", "14 03077a1c6bac60e6f514691634a7f6eb5c85aae8 m \n", "15 03077a1c6bac60e6f514691634a7f6eb5c85aae8 m \n", "16 352d0cf7f3e9be14dad7df644ad65efc27605ae2 m \n", "17 352d0cf7f3e9be14dad7df644ad65efc27605ae2 m \n", "18 03077a1c6bac60e6f514691634a7f6eb5c85aae8 m \n", "19 03077a1c6bac60e6f514691634a7f6eb5c85aae8 m \n", "20 03077a1c6bac60e6f514691634a7f6eb5c85aae8 m \n", "21 352d0cf7f3e9be14dad7df644ad65efc27605ae2 m \n", "22 352d0cf7f3e9be14dad7df644ad65efc27605ae2 m \n", "23 352d0cf7f3e9be14dad7df644ad65efc27605ae2 m \n", "24 352d0cf7f3e9be14dad7df644ad65efc27605ae2 m \n", "25 352d0cf7f3e9be14dad7df644ad65efc27605ae2 m \n", "26 352d0cf7f3e9be14dad7df644ad65efc27605ae2 m \n", "27 352d0cf7f3e9be14dad7df644ad65efc27605ae2 m \n", "28 352d0cf7f3e9be14dad7df644ad65efc27605ae2 m \n", "\n", " altitude_low_meters altitude_high_meters altitude_mean_meters \n", "1 1488.0 1488.0 1488.0 \n", "2 3170.0 3170.0 3170.0 \n", "3 1000.0 1000.0 1000.0 \n", "4 1212.0 1212.0 1212.0 \n", "5 1200.0 1300.0 1250.0 \n", "6 3000.0 3000.0 3000.0 \n", "7 750.0 750.0 750.0 \n", "8 3140.0 3140.0 3140.0 \n", "9 1000.0 1000.0 1000.0 \n", "10 900.0 1300.0 1100.0 \n", "11 1095.0 1095.0 1095.0 \n", "12 1000.0 1000.0 1000.0 \n", "13 750.0 750.0 750.0 \n", "14 1367.0 1367.0 1367.0 \n", "15 1488.0 1488.0 1488.0 \n", "16 1000.0 1000.0 1000.0 \n", "17 750.0 750.0 750.0 \n", "18 1600.0 1600.0 1600.0 \n", "19 1745.0 1745.0 1745.0 \n", "20 1200.0 1200.0 1200.0 \n", "21 750.0 750.0 750.0 \n", "22 750.0 750.0 750.0 \n", "23 3000.0 3000.0 3000.0 \n", "24 NaN NaN NaN \n", "25 40.0 40.0 40.0 \n", "26 795.0 795.0 795.0 \n", "27 NaN NaN NaN \n", "28 NaN NaN NaN \n", "\n", "[28 rows x 43 columns]" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "coffee_df = pd.read_csv(coffee_data_url,index_col=0)\n", "coffee_df" ] }, { "cell_type": "code", "execution_count": 12, "id": "00a2edec", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Int64Index([ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,\n", " 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28],\n", " dtype='int64')" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "coffee_df.index" ] }, { "cell_type": "markdown", "id": "3e4c370d", "metadata": {}, "source": [ "Now it's neater\n", "\n", "\n", "## Extracting Parts of Data Frames\n", "\n", "We can look at the first 5 rows with `head`" ] }, { "cell_type": "code", "execution_count": 13, "id": "5e82c25e", "metadata": {}, "outputs": [ { "data": { "text/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", " \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", " \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", " \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", "
SpeciesOwnerCountry.of.OriginFarm.NameLot.NumberMillICO.NumberCompanyAltitudeRegion...ColorCategory.Two.DefectsExpirationCertification.BodyCertification.AddressCertification.Contactunit_of_measurementaltitude_low_metersaltitude_high_metersaltitude_mean_meters
1Robustaankole coffee producers coopUgandakyangundu cooperative societyNaNankole coffee producers0ankole coffee producers coop1488sheema south western...Green2June 26th, 2015Uganda Coffee Development Authoritye36d0270932c3b657e96b7b0278dfd85dc0fe74303077a1c6bac60e6f514691634a7f6eb5c85aae8m1488.01488.01488.0
2Robustanishant gurjerIndiasethuraman estate kaapi royale25sethuraman estate14/1148/2017/21kaapi royale3170chikmagalur karnataka indua...NaN2October 31st, 2018Specialty Coffee Associationff7c18ad303d4b603ac3f8cff7e611ffc735e720352d0cf7f3e9be14dad7df644ad65efc27605ae2m3170.03170.03170.0
3Robustaandrew hetzelIndiasethuraman estateNaNNaN0000sethuraman estate1000mchikmagalur...Green0April 29th, 2016Specialty Coffee Associationff7c18ad303d4b603ac3f8cff7e611ffc735e720352d0cf7f3e9be14dad7df644ad65efc27605ae2m1000.01000.01000.0
4RobustaugacofUgandaugacof project areaNaNugacof0ugacof ltd1212central...Green7July 14th, 2015Uganda Coffee Development Authoritye36d0270932c3b657e96b7b0278dfd85dc0fe74303077a1c6bac60e6f514691634a7f6eb5c85aae8m1212.01212.01212.0
5Robustakatuka development trust ltdUgandakatikamu capca farmers associationNaNkatuka development trust0katuka development trust ltd1200-1300luwero central region...Green3June 26th, 2015Uganda Coffee Development Authoritye36d0270932c3b657e96b7b0278dfd85dc0fe74303077a1c6bac60e6f514691634a7f6eb5c85aae8m1200.01300.01250.0
\n", "

5 rows × 43 columns

\n", "
" ], "text/plain": [ " Species Owner Country.of.Origin \\\n", "1 Robusta ankole coffee producers coop Uganda \n", "2 Robusta nishant gurjer India \n", "3 Robusta andrew hetzel India \n", "4 Robusta ugacof Uganda \n", "5 Robusta katuka development trust ltd Uganda \n", "\n", " Farm.Name Lot.Number Mill \\\n", "1 kyangundu cooperative society NaN ankole coffee producers \n", "2 sethuraman estate kaapi royale 25 sethuraman estate \n", "3 sethuraman estate NaN NaN \n", "4 ugacof project area NaN ugacof \n", "5 katikamu capca farmers association NaN katuka development trust \n", "\n", " ICO.Number Company Altitude \\\n", "1 0 ankole coffee producers coop 1488 \n", "2 14/1148/2017/21 kaapi royale 3170 \n", "3 0000 sethuraman estate 1000m \n", "4 0 ugacof ltd 1212 \n", "5 0 katuka development trust ltd 1200-1300 \n", "\n", " Region ... Color Category.Two.Defects \\\n", "1 sheema south western ... Green 2 \n", "2 chikmagalur karnataka indua ... NaN 2 \n", "3 chikmagalur ... Green 0 \n", "4 central ... Green 7 \n", "5 luwero central region ... Green 3 \n", "\n", " Expiration Certification.Body \\\n", "1 June 26th, 2015 Uganda Coffee Development Authority \n", "2 October 31st, 2018 Specialty Coffee Association \n", "3 April 29th, 2016 Specialty Coffee Association \n", "4 July 14th, 2015 Uganda Coffee Development Authority \n", "5 June 26th, 2015 Uganda Coffee Development Authority \n", "\n", " Certification.Address \\\n", "1 e36d0270932c3b657e96b7b0278dfd85dc0fe743 \n", "2 ff7c18ad303d4b603ac3f8cff7e611ffc735e720 \n", "3 ff7c18ad303d4b603ac3f8cff7e611ffc735e720 \n", "4 e36d0270932c3b657e96b7b0278dfd85dc0fe743 \n", "5 e36d0270932c3b657e96b7b0278dfd85dc0fe743 \n", "\n", " Certification.Contact unit_of_measurement \\\n", "1 03077a1c6bac60e6f514691634a7f6eb5c85aae8 m \n", "2 352d0cf7f3e9be14dad7df644ad65efc27605ae2 m \n", "3 352d0cf7f3e9be14dad7df644ad65efc27605ae2 m \n", "4 03077a1c6bac60e6f514691634a7f6eb5c85aae8 m \n", "5 03077a1c6bac60e6f514691634a7f6eb5c85aae8 m \n", "\n", " altitude_low_meters altitude_high_meters altitude_mean_meters \n", "1 1488.0 1488.0 1488.0 \n", "2 3170.0 3170.0 3170.0 \n", "3 1000.0 1000.0 1000.0 \n", "4 1212.0 1212.0 1212.0 \n", "5 1200.0 1300.0 1250.0 \n", "\n", "[5 rows x 43 columns]" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "coffee_df.head()" ] }, { "cell_type": "markdown", "id": "e3c0c592", "metadata": {}, "source": [ "````{margin}\n", "```{admonition} Try it yourself\n", "How can you look at the first 3 or last 2 rows?\n", "```\n", "````\n", "\n", "and the last 5 with `tail`" ] }, { "cell_type": "code", "execution_count": 14, "id": "713a3570", "metadata": {}, "outputs": [ { "data": { "text/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", " \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", " \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", " \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", "
SpeciesOwnerCountry.of.OriginFarm.NameLot.NumberMillICO.NumberCompanyAltitudeRegion...ColorCategory.Two.DefectsExpirationCertification.BodyCertification.AddressCertification.Contactunit_of_measurementaltitude_low_metersaltitude_high_metersaltitude_mean_meters
24Robustaluis roblesEcuadorrobustasaLavado 1our own labNaNrobustasaNaNsan juan, playas...Blue-Green1January 18th, 2017Specialty Coffee Associationff7c18ad303d4b603ac3f8cff7e611ffc735e720352d0cf7f3e9be14dad7df644ad65efc27605ae2mNaNNaNNaN
25Robustaluis roblesEcuadorrobustasaLavado 3own laboratoryNaNrobustasa40san juan, playas...Blue-Green0January 18th, 2017Specialty Coffee Associationff7c18ad303d4b603ac3f8cff7e611ffc735e720352d0cf7f3e9be14dad7df644ad65efc27605ae2m40.040.040.0
26Robustajames mooreUnited Statesfazenda cazengoNaNcafe cazengoNaNglobal opportunity fund795 meterskwanza norte province, angola...NaN6December 23rd, 2015Specialty Coffee Associationff7c18ad303d4b603ac3f8cff7e611ffc735e720352d0cf7f3e9be14dad7df644ad65efc27605ae2m795.0795.0795.0
27Robustacafe politicoIndiaNaNNaNNaN14-1118-2014-0087cafe politicoNaNNaN...Green1August 25th, 2015Specialty Coffee Associationff7c18ad303d4b603ac3f8cff7e611ffc735e720352d0cf7f3e9be14dad7df644ad65efc27605ae2mNaNNaNNaN
28Robustacafe politicoVietnamNaNNaNNaNNaNcafe politicoNaNNaN...None9August 25th, 2015Specialty Coffee Associationff7c18ad303d4b603ac3f8cff7e611ffc735e720352d0cf7f3e9be14dad7df644ad65efc27605ae2mNaNNaNNaN
\n", "

5 rows × 43 columns

\n", "
" ], "text/plain": [ " Species Owner Country.of.Origin Farm.Name Lot.Number \\\n", "24 Robusta luis robles Ecuador robustasa Lavado 1 \n", "25 Robusta luis robles Ecuador robustasa Lavado 3 \n", "26 Robusta james moore United States fazenda cazengo NaN \n", "27 Robusta cafe politico India NaN NaN \n", "28 Robusta cafe politico Vietnam NaN NaN \n", "\n", " Mill ICO.Number Company Altitude \\\n", "24 our own lab NaN robustasa NaN \n", "25 own laboratory NaN robustasa 40 \n", "26 cafe cazengo NaN global opportunity fund 795 meters \n", "27 NaN 14-1118-2014-0087 cafe politico NaN \n", "28 NaN NaN cafe politico NaN \n", "\n", " Region ... Color Category.Two.Defects \\\n", "24 san juan, playas ... Blue-Green 1 \n", "25 san juan, playas ... Blue-Green 0 \n", "26 kwanza norte province, angola ... NaN 6 \n", "27 NaN ... Green 1 \n", "28 NaN ... None 9 \n", "\n", " Expiration Certification.Body \\\n", "24 January 18th, 2017 Specialty Coffee Association \n", "25 January 18th, 2017 Specialty Coffee Association \n", "26 December 23rd, 2015 Specialty Coffee Association \n", "27 August 25th, 2015 Specialty Coffee Association \n", "28 August 25th, 2015 Specialty Coffee Association \n", "\n", " Certification.Address \\\n", "24 ff7c18ad303d4b603ac3f8cff7e611ffc735e720 \n", "25 ff7c18ad303d4b603ac3f8cff7e611ffc735e720 \n", "26 ff7c18ad303d4b603ac3f8cff7e611ffc735e720 \n", "27 ff7c18ad303d4b603ac3f8cff7e611ffc735e720 \n", "28 ff7c18ad303d4b603ac3f8cff7e611ffc735e720 \n", "\n", " Certification.Contact unit_of_measurement \\\n", "24 352d0cf7f3e9be14dad7df644ad65efc27605ae2 m \n", "25 352d0cf7f3e9be14dad7df644ad65efc27605ae2 m \n", "26 352d0cf7f3e9be14dad7df644ad65efc27605ae2 m \n", "27 352d0cf7f3e9be14dad7df644ad65efc27605ae2 m \n", "28 352d0cf7f3e9be14dad7df644ad65efc27605ae2 m \n", "\n", " altitude_low_meters altitude_high_meters altitude_mean_meters \n", "24 NaN NaN NaN \n", "25 40.0 40.0 40.0 \n", "26 795.0 795.0 795.0 \n", "27 NaN NaN NaN \n", "28 NaN NaN NaN \n", "\n", "[5 rows x 43 columns]" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "coffee_df.tail()" ] }, { "cell_type": "markdown", "id": "da74b345", "metadata": {}, "source": [ "the shape of a DataFrame is an attribute" ] }, { "cell_type": "code", "execution_count": 15, "id": "30d0d549", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(28, 43)" ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "coffee_df.shape" ] }, { "cell_type": "code", "execution_count": 16, "id": "c016f853", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "28" ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "len(coffee_df)" ] }, { "cell_type": "markdown", "id": "aef93865", "metadata": {}, "source": [ "We can pick out columns by name." ] }, { "cell_type": "code", "execution_count": 17, "id": "29cf4ad6", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "1 Robusta\n", "2 Robusta\n", "3 Robusta\n", "4 Robusta\n", "5 Robusta\n", "6 Robusta\n", "7 Robusta\n", "8 Robusta\n", "9 Robusta\n", "10 Robusta\n", "11 Robusta\n", "12 Robusta\n", "13 Robusta\n", "14 Robusta\n", "15 Robusta\n", "16 Robusta\n", "17 Robusta\n", "18 Robusta\n", "19 Robusta\n", "20 Robusta\n", "21 Robusta\n", "22 Robusta\n", "23 Robusta\n", "24 Robusta\n", "25 Robusta\n", "26 Robusta\n", "27 Robusta\n", "28 Robusta\n", "Name: Species, dtype: object" ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "coffee_df['Species']" ] }, { "cell_type": "markdown", "id": "3889bb38", "metadata": {}, "source": [ "```{important}\n", "We did not do this step in class\n", "```\n", "\n", "We can pick out rows with `loc`" ] }, { "cell_type": "code", "execution_count": 18, "id": "0f010187", "metadata": {}, "outputs": [ { "ename": "KeyError", "evalue": "0", "output_type": "error", "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31mKeyError\u001b[0m Traceback (most recent call last)", "File \u001b[0;32m/opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/pandas/core/indexes/base.py:3803\u001b[0m, in \u001b[0;36mIndex.get_loc\u001b[0;34m(self, key, method, tolerance)\u001b[0m\n\u001b[1;32m 3802\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[0;32m-> 3803\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_engine\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mget_loc\u001b[49m\u001b[43m(\u001b[49m\u001b[43mcasted_key\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 3804\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mKeyError\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m err:\n", "File \u001b[0;32m/opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/pandas/_libs/index.pyx:138\u001b[0m, in \u001b[0;36mpandas._libs.index.IndexEngine.get_loc\u001b[0;34m()\u001b[0m\n", "File \u001b[0;32m/opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/pandas/_libs/index.pyx:165\u001b[0m, in \u001b[0;36mpandas._libs.index.IndexEngine.get_loc\u001b[0;34m()\u001b[0m\n", "File \u001b[0;32mpandas/_libs/hashtable_class_helper.pxi:2263\u001b[0m, in \u001b[0;36mpandas._libs.hashtable.Int64HashTable.get_item\u001b[0;34m()\u001b[0m\n", "File \u001b[0;32mpandas/_libs/hashtable_class_helper.pxi:2273\u001b[0m, in \u001b[0;36mpandas._libs.hashtable.Int64HashTable.get_item\u001b[0;34m()\u001b[0m\n", "\u001b[0;31mKeyError\u001b[0m: 0", "\nThe above exception was the direct cause of the following exception:\n", "\u001b[0;31mKeyError\u001b[0m Traceback (most recent call last)", "Cell \u001b[0;32mIn[18], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[43mcoffee_df\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mloc\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;241;43m0\u001b[39;49m\u001b[43m]\u001b[49m\n", "File \u001b[0;32m/opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/pandas/core/indexing.py:1073\u001b[0m, in \u001b[0;36m_LocationIndexer.__getitem__\u001b[0;34m(self, key)\u001b[0m\n\u001b[1;32m 1070\u001b[0m axis \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39maxis \u001b[38;5;129;01mor\u001b[39;00m \u001b[38;5;241m0\u001b[39m\n\u001b[1;32m 1072\u001b[0m maybe_callable \u001b[38;5;241m=\u001b[39m com\u001b[38;5;241m.\u001b[39mapply_if_callable(key, \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mobj)\n\u001b[0;32m-> 1073\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_getitem_axis\u001b[49m\u001b[43m(\u001b[49m\u001b[43mmaybe_callable\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43maxis\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43maxis\u001b[49m\u001b[43m)\u001b[49m\n", "File \u001b[0;32m/opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/pandas/core/indexing.py:1312\u001b[0m, in \u001b[0;36m_LocIndexer._getitem_axis\u001b[0;34m(self, key, axis)\u001b[0m\n\u001b[1;32m 1310\u001b[0m \u001b[38;5;66;03m# fall thru to straight lookup\u001b[39;00m\n\u001b[1;32m 1311\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_validate_key(key, axis)\n\u001b[0;32m-> 1312\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_get_label\u001b[49m\u001b[43m(\u001b[49m\u001b[43mkey\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43maxis\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43maxis\u001b[49m\u001b[43m)\u001b[49m\n", "File \u001b[0;32m/opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/pandas/core/indexing.py:1260\u001b[0m, in \u001b[0;36m_LocIndexer._get_label\u001b[0;34m(self, label, axis)\u001b[0m\n\u001b[1;32m 1258\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21m_get_label\u001b[39m(\u001b[38;5;28mself\u001b[39m, label, axis: \u001b[38;5;28mint\u001b[39m):\n\u001b[1;32m 1259\u001b[0m \u001b[38;5;66;03m# GH#5567 this will fail if the label is not present in the axis.\u001b[39;00m\n\u001b[0;32m-> 1260\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mobj\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mxs\u001b[49m\u001b[43m(\u001b[49m\u001b[43mlabel\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43maxis\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43maxis\u001b[49m\u001b[43m)\u001b[49m\n", "File \u001b[0;32m/opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/pandas/core/generic.py:4056\u001b[0m, in \u001b[0;36mNDFrame.xs\u001b[0;34m(self, key, axis, level, drop_level)\u001b[0m\n\u001b[1;32m 4054\u001b[0m new_index \u001b[38;5;241m=\u001b[39m index[loc]\n\u001b[1;32m 4055\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[0;32m-> 4056\u001b[0m loc \u001b[38;5;241m=\u001b[39m \u001b[43mindex\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mget_loc\u001b[49m\u001b[43m(\u001b[49m\u001b[43mkey\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 4058\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(loc, np\u001b[38;5;241m.\u001b[39mndarray):\n\u001b[1;32m 4059\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m loc\u001b[38;5;241m.\u001b[39mdtype \u001b[38;5;241m==\u001b[39m np\u001b[38;5;241m.\u001b[39mbool_:\n", "File \u001b[0;32m/opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/pandas/core/indexes/base.py:3805\u001b[0m, in \u001b[0;36mIndex.get_loc\u001b[0;34m(self, key, method, tolerance)\u001b[0m\n\u001b[1;32m 3803\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_engine\u001b[38;5;241m.\u001b[39mget_loc(casted_key)\n\u001b[1;32m 3804\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mKeyError\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m err:\n\u001b[0;32m-> 3805\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mKeyError\u001b[39;00m(key) \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01merr\u001b[39;00m\n\u001b[1;32m 3806\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mTypeError\u001b[39;00m:\n\u001b[1;32m 3807\u001b[0m \u001b[38;5;66;03m# If we have a listlike key, _check_indexing_error will raise\u001b[39;00m\n\u001b[1;32m 3808\u001b[0m \u001b[38;5;66;03m# InvalidIndexError. Otherwise we fall through and re-raise\u001b[39;00m\n\u001b[1;32m 3809\u001b[0m \u001b[38;5;66;03m# the TypeError.\u001b[39;00m\n\u001b[1;32m 3810\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_check_indexing_error(key)\n", "\u001b[0;31mKeyError\u001b[0m: 0" ] } ], "source": [ "coffee_df.loc[0]" ] }, { "cell_type": "markdown", "id": "e62c61ed", "metadata": {}, "source": [ "## Reading data from websites\n", "\n", "We'll first read from the course website.\n", "```{note}\n", "This is our first bit of web scraping!\n", "We will do more, but for very structured data it can be this easy\n", "```" ] }, { "cell_type": "code", "execution_count": 19, "id": "3d49993b", "metadata": {}, "outputs": [], "source": [ "comm_url = 'https://rhodyprog4ds.github.io/BrownFall22/syllabus/communication.html#'" ] }, { "cell_type": "markdown", "id": "a491ecdb", "metadata": {}, "source": [ "So far, we've read data in from a .csv file with `pd.read_csv` and created a DataFrame with the constructor `pd.DataFrame` using a dictionary. Pandas provides many interfaces for reading in data. They're described on the [Pandas IO page](https://pandas.pydata.org/docs/reference/io.html).\n", "\n", "````{margin}\n", "```{note}\n", "Using the documentation for a library (and the base language) is\n", "totally expected and normal part of programming. That's what you\n", "should use as your primary source for questions in this class. Other\n", "sources can become outdated pretty quickly as the language changes, but\n", "most of the libraries we'll use have processes in place to ensure that\n", "their own documentation gets updated at the same time the code does.\n", "```\n", "\n", "```{warning}\n", "If you use other sources and get advised to solutions that are deprecated you may not earn achievements for that work.\n", "```\n", "````\n", "\n", "We can use the `read_html` method to read from this page. We know that it has multiple tables on the page, and from the help, we know that it will return a list of DataFrames." ] }, { "cell_type": "code", "execution_count": 20, "id": "d419d662", "metadata": {}, "outputs": [], "source": [ "df_list = pd.read_html(comm_url)" ] }, { "cell_type": "markdown", "id": "5f09fb53", "metadata": {}, "source": [ "We can also verify what it returns" ] }, { "cell_type": "code", "execution_count": 21, "id": "af338269", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "list" ] }, "execution_count": 21, "metadata": {}, "output_type": "execute_result" } ], "source": [ "type(df_list)" ] }, { "cell_type": "markdown", "id": "a654abe1", "metadata": {}, "source": [ "We can index with `[]` to pick one item from the list and verify that it is a DataFrame." ] }, { "cell_type": "code", "execution_count": 22, "id": "b4f1a399", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "pandas.core.frame.DataFrame" ] }, "execution_count": 22, "metadata": {}, "output_type": "execute_result" } ], "source": [ "type(df_list[0])" ] }, { "cell_type": "markdown", "id": "1559d833", "metadata": {}, "source": [ "## Pythonic Loops\n", "\n", "In Python, loops do not require an iterator variable. It has an interable object and a loop variable.\n", "\n", "```Python\n", "for loop_variable in iterable_object:\n", " # loop body\n", "```\n", "\n", "the `loop_variable` takes on the value of each item in the `iterable_object`\n", "each time it goes through, in order. Writing loops this way makes them more\n", "compact and more readable, this is more like English. For example:" ] }, { "cell_type": "code", "execution_count": 23, "id": "324e1562", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "S\n", "A\n", "R\n", "A\n", "H\n" ] } ], "source": [ "name = 'sarah'\n", "for letter in name:\n", " print(letter.upper())" ] }, { "cell_type": "markdown", "id": "f11afb11", "metadata": {}, "source": [ "It is best to name variables so that the loop variable makes sense as an item from the iterable. For example, names have letters in them, and an item in `df_list` makes sense as `df`." ] }, { "cell_type": "code", "execution_count": 24, "id": "3311d72e", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "(6, 4)\n", "(6, 4)\n", "(1, 3)\n", "(3, 3)\n", "(2, 3)\n" ] } ], "source": [ "for df in df_list:\n", " print(df.shape)" ] }, { "cell_type": "markdown", "id": "44cff92e", "metadata": {}, "source": [ "## Types Solution\n", "\n", "\n", "```{warning}\n", "I am using bad variable names here `a`, `b` ,... because these are only as options for a question and we will not use them again\n", "```\n", "\n", "````{margin}\n", "This is called a list comprehension. It allows you to build a list using a for loop all in one step.\n", "````" ] }, { "cell_type": "code", "execution_count": 25, "id": "dfd00439", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['a', 'b', 'c', 'd', 'e']" ] }, "execution_count": 25, "metadata": {}, "output_type": "execute_result" } ], "source": [ "a = [char for char in 'abcde']\n", "a" ] }, { "cell_type": "code", "execution_count": 26, "id": "429f77f4", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "list" ] }, "execution_count": 26, "metadata": {}, "output_type": "execute_result" } ], "source": [ "type(a)" ] }, { "cell_type": "markdown", "id": "b838487b", "metadata": {}, "source": [ "````{margin}\n", "This is called a dictionary comprehension. It allows you to build a dictionary using a for loop all in one step.\n", "````" ] }, { "cell_type": "code", "execution_count": 27, "id": "87e5ea58", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4}" ] }, "execution_count": 27, "metadata": {}, "output_type": "execute_result" } ], "source": [ "b = {char:i for i, char in enumerate('abcde')}\n", "b" ] }, { "cell_type": "code", "execution_count": 28, "id": "b960e1c5", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "dict" ] }, "execution_count": 28, "metadata": {}, "output_type": "execute_result" } ], "source": [ "type(b)" ] }, { "cell_type": "code", "execution_count": 29, "id": "5c33a5c5", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "('a', 'b', 'c', 'd', 'e')" ] }, "execution_count": 29, "metadata": {}, "output_type": "execute_result" } ], "source": [ "c = ('a','b','c','d','e')\n", "c" ] }, { "cell_type": "code", "execution_count": 30, "id": "97a09200", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "tuple" ] }, "execution_count": 30, "metadata": {}, "output_type": "execute_result" } ], "source": [ "type(c)" ] }, { "cell_type": "code", "execution_count": 31, "id": "49eaa09b", "metadata": {}, "outputs": [ { "ename": "ValueError", "evalue": "empty separator", "output_type": "error", "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)", "Cell \u001b[0;32mIn[31], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m d \u001b[38;5;241m=\u001b[39m \u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43ma b c d e\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43msplit\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m)\u001b[49m\n\u001b[1;32m 2\u001b[0m d\n", "\u001b[0;31mValueError\u001b[0m: empty separator" ] } ], "source": [ "d = 'a b c d e'.split('')\n", "d" ] }, { "cell_type": "code", "execution_count": 32, "id": "fb72bbe0", "metadata": {}, "outputs": [ { "ename": "NameError", "evalue": "name 'd' is not defined", "output_type": "error", "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)", "Cell \u001b[0;32mIn[32], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[38;5;28mtype\u001b[39m(\u001b[43md\u001b[49m)\n", "\u001b[0;31mNameError\u001b[0m: name 'd' is not defined" ] } ], "source": [ "type(d)" ] }, { "cell_type": "code", "execution_count": null, "id": "d2cd4e2d", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "id": "bc15afd1", "metadata": {}, "source": [ "## Questions After Class\n", "\n", "### what is a dictionary in python?\n", "\n", "a dictionary is a datatype from base python that stores key, value pairs.\n", "\n", "For example" ] }, { "cell_type": "code", "execution_count": 33, "id": "d8f77490", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'first': 'Sarah', 'last': 'Brown', 'title': 'Dr.'}" ] }, "execution_count": 33, "metadata": {}, "output_type": "execute_result" } ], "source": [ "prof_info = {'first':'Sarah', 'last':'Brown', 'title':'Dr.'}\n", "prof_info" ] }, { "cell_type": "markdown", "id": "ff40648e", "metadata": {}, "source": [ "We can use the keys to index in and get the values out" ] }, { "cell_type": "code", "execution_count": 34, "id": "228bd58e", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'Dr.'" ] }, "execution_count": 34, "metadata": {}, "output_type": "execute_result" } ], "source": [ "prof_info['title']" ] }, { "cell_type": "markdown", "id": "67ec7233", "metadata": {}, "source": [ "Even though we will mostly use DataFrame, dictionaries and other base python types are important. Dictionaries are very powerful they can hold whole functions in them. For example, the Python language does not have a switch case (which can be used for handling many if/else cases) but instead dictionaries can be used for that.\n", "\n", "```{admonition} Further Reading\n", "You can read more about the [details of data types](https://pandas.pydata.org/docs/user_guide/basics.html#basics-dtypes) in Pandas in the documentation\n", "```\n", "\n", "### How to see unique values in a column\n", "\n", "We will get to this soon! We got the first part, picking out a single column to look at, we will see the method for that probably on Monday, but maybe on Friday." ] } ], "metadata": { "jupytext": { "text_representation": { "extension": ".md", "format_name": "myst", "format_version": 0.13, "jupytext_version": "1.14.1" } }, "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.9.16" }, "source_map": [ 12, 19, 23, 27, 29, 37, 41, 44, 51, 53, 59, 61, 64, 66, 72, 74, 79, 81, 85, 90, 92, 99, 101, 110, 112, 115, 119, 121, 124, 126, 133, 135, 145, 147, 170, 172, 176, 178, 181, 183, 198, 202, 206, 209, 222, 228, 230, 235, 240, 244, 249, 253, 258, 262, 264, 276, 279, 283, 285 ] }, "nbformat": 4, "nbformat_minor": 5 }