{ "cells": [ { "cell_type": "markdown", "metadata": { "papermill": { "duration": 0.036894, "end_time": "2020-10-19T19:10:12.857060", "exception": false, "start_time": "2020-10-19T19:10:12.820166", "status": "completed" }, "tags": [] }, "source": [ "# Introduction\n", "\n", "Selecting specific values of a pandas DataFrame or Series to work on is an implicit step in almost any data operation you'll run, so one of the first things you need to learn in working with data in Python is how to go about selecting the data points relevant to you quickly and effectively." ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "_kg_hide-input": true, "execution": { "iopub.execute_input": "2020-10-19T19:10:12.935721Z", "iopub.status.busy": "2020-10-19T19:10:12.934939Z", "iopub.status.idle": "2020-10-19T19:10:14.543274Z", "shell.execute_reply": "2020-10-19T19:10:14.542567Z" }, "papermill": { "duration": 1.652041, "end_time": "2020-10-19T19:10:14.543405", "exception": false, "start_time": "2020-10-19T19:10:12.891364", "status": "completed" }, "tags": [] }, "outputs": [], "source": [ "\n", "import pandas as pd\n", "reviews = pd.read_csv(\"../input/wine-reviews/winemag-data-130k-v2.csv\", index_col=0)\n", "pd.set_option('max_rows', 5)" ] }, { "cell_type": "markdown", "metadata": { "papermill": { "duration": 0.042936, "end_time": "2020-10-19T19:10:14.621420", "exception": false, "start_time": "2020-10-19T19:10:14.578484", "status": "completed" }, "tags": [] }, "source": [ "**To start the exercise for this topic, please click [here](https://www.kaggle.com/kernels/fork/587910).**" ] }, { "cell_type": "markdown", "metadata": { "papermill": { "duration": 0.041952, "end_time": "2020-10-19T19:10:14.713532", "exception": false, "start_time": "2020-10-19T19:10:14.671580", "status": "completed" }, "tags": [] }, "source": [ "# Native accessors\n", "\n", "Native Python objects provide good ways of indexing data. Pandas carries all of these over, which helps make it easy to start with.\n", "\n", "Consider this DataFrame:" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": true, "execution": { "iopub.execute_input": "2020-10-19T19:10:14.813190Z", "iopub.status.busy": "2020-10-19T19:10:14.812396Z", "iopub.status.idle": "2020-10-19T19:10:14.831381Z", "shell.execute_reply": "2020-10-19T19:10:14.830700Z" }, "jupyter": { "outputs_hidden": true }, "papermill": { "duration": 0.082945, "end_time": "2020-10-19T19:10:14.831541", "exception": false, "start_time": "2020-10-19T19:10:14.748596", "status": "completed" }, "tags": [] }, "outputs": [ { "data": { "text/html": [ "
\n", " | country | \n", "description | \n", "designation | \n", "points | \n", "price | \n", "province | \n", "region_1 | \n", "region_2 | \n", "taster_name | \n", "taster_twitter_handle | \n", "title | \n", "variety | \n", "winery | \n", "
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | \n", "Italy | \n", "Aromas include tropical fruit, broom, brimston... | \n", "Vulkà Bianco | \n", "87 | \n", "NaN | \n", "Sicily & Sardinia | \n", "Etna | \n", "NaN | \n", "Kerin O’Keefe | \n", "@kerinokeefe | \n", "Nicosia 2013 Vulkà Bianco (Etna) | \n", "White Blend | \n", "Nicosia | \n", "
1 | \n", "Portugal | \n", "This is ripe and fruity, a wine that is smooth... | \n", "Avidagos | \n", "87 | \n", "15.0 | \n", "Douro | \n", "NaN | \n", "NaN | \n", "Roger Voss | \n", "@vossroger | \n", "Quinta dos Avidagos 2011 Avidagos Red (Douro) | \n", "Portuguese Red | \n", "Quinta dos Avidagos | \n", "
... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "
129969 | \n", "France | \n", "A dry style of Pinot Gris, this is crisp with ... | \n", "NaN | \n", "90 | \n", "32.0 | \n", "Alsace | \n", "Alsace | \n", "NaN | \n", "Roger Voss | \n", "@vossroger | \n", "Domaine Marcel Deiss 2012 Pinot Gris (Alsace) | \n", "Pinot Gris | \n", "Domaine Marcel Deiss | \n", "
129970 | \n", "France | \n", "Big, rich and off-dry, this is powered by inte... | \n", "Lieu-dit Harth Cuvée Caroline | \n", "90 | \n", "21.0 | \n", "Alsace | \n", "Alsace | \n", "NaN | \n", "Roger Voss | \n", "@vossroger | \n", "Domaine Schoffit 2012 Lieu-dit Harth Cuvée Car... | \n", "Gewürztraminer | \n", "Domaine Schoffit | \n", "
129971 rows × 13 columns
\n", "\n", " | country | \n", "description | \n", "designation | \n", "points | \n", "price | \n", "province | \n", "region_1 | \n", "region_2 | \n", "taster_name | \n", "taster_twitter_handle | \n", "title | \n", "variety | \n", "winery | \n", "
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
129966 | \n", "Germany | \n", "Notes of honeysuckle and cantaloupe sweeten th... | \n", "Brauneberger Juffer-Sonnenuhr Spätlese | \n", "90 | \n", "28.0 | \n", "Mosel | \n", "NaN | \n", "NaN | \n", "Anna Lee C. Iijima | \n", "NaN | \n", "Dr. H. Thanisch (Erben Müller-Burggraef) 2013 ... | \n", "Riesling | \n", "Dr. H. Thanisch (Erben Müller-Burggraef) | \n", "
129967 | \n", "US | \n", "Citation is given as much as a decade of bottl... | \n", "NaN | \n", "90 | \n", "75.0 | \n", "Oregon | \n", "Oregon | \n", "Oregon Other | \n", "Paul Gregutt | \n", "@paulgwine | \n", "Citation 2004 Pinot Noir (Oregon) | \n", "Pinot Noir | \n", "Citation | \n", "
129968 | \n", "France | \n", "Well-drained gravel soil gives this wine its c... | \n", "Kritt | \n", "90 | \n", "30.0 | \n", "Alsace | \n", "Alsace | \n", "NaN | \n", "Roger Voss | \n", "@vossroger | \n", "Domaine Gresser 2013 Kritt Gewurztraminer (Als... | \n", "Gewürztraminer | \n", "Domaine Gresser | \n", "
129969 | \n", "France | \n", "A dry style of Pinot Gris, this is crisp with ... | \n", "NaN | \n", "90 | \n", "32.0 | \n", "Alsace | \n", "Alsace | \n", "NaN | \n", "Roger Voss | \n", "@vossroger | \n", "Domaine Marcel Deiss 2012 Pinot Gris (Alsace) | \n", "Pinot Gris | \n", "Domaine Marcel Deiss | \n", "
129970 | \n", "France | \n", "Big, rich and off-dry, this is powered by inte... | \n", "Lieu-dit Harth Cuvée Caroline | \n", "90 | \n", "21.0 | \n", "Alsace | \n", "Alsace | \n", "NaN | \n", "Roger Voss | \n", "@vossroger | \n", "Domaine Schoffit 2012 Lieu-dit Harth Cuvée Car... | \n", "Gewürztraminer | \n", "Domaine Schoffit | \n", "
\n", " | taster_name | \n", "taster_twitter_handle | \n", "points | \n", "
---|---|---|---|
0 | \n", "Kerin O’Keefe | \n", "@kerinokeefe | \n", "87 | \n", "
1 | \n", "Roger Voss | \n", "@vossroger | \n", "87 | \n", "
... | \n", "... | \n", "... | \n", "... | \n", "
129969 | \n", "Roger Voss | \n", "@vossroger | \n", "90 | \n", "
129970 | \n", "Roger Voss | \n", "@vossroger | \n", "90 | \n", "
129971 rows × 3 columns
\n", "\n", " | country | \n", "description | \n", "designation | \n", "points | \n", "price | \n", "province | \n", "region_1 | \n", "region_2 | \n", "taster_name | \n", "taster_twitter_handle | \n", "variety | \n", "winery | \n", "
---|---|---|---|---|---|---|---|---|---|---|---|---|
title | \n", "\n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " |
Nicosia 2013 Vulkà Bianco (Etna) | \n", "Italy | \n", "Aromas include tropical fruit, broom, brimston... | \n", "Vulkà Bianco | \n", "87 | \n", "NaN | \n", "Sicily & Sardinia | \n", "Etna | \n", "NaN | \n", "Kerin O’Keefe | \n", "@kerinokeefe | \n", "White Blend | \n", "Nicosia | \n", "
Quinta dos Avidagos 2011 Avidagos Red (Douro) | \n", "Portugal | \n", "This is ripe and fruity, a wine that is smooth... | \n", "Avidagos | \n", "87 | \n", "15.0 | \n", "Douro | \n", "NaN | \n", "NaN | \n", "Roger Voss | \n", "@vossroger | \n", "Portuguese Red | \n", "Quinta dos Avidagos | \n", "
... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "
Domaine Marcel Deiss 2012 Pinot Gris (Alsace) | \n", "France | \n", "A dry style of Pinot Gris, this is crisp with ... | \n", "NaN | \n", "90 | \n", "32.0 | \n", "Alsace | \n", "Alsace | \n", "NaN | \n", "Roger Voss | \n", "@vossroger | \n", "Pinot Gris | \n", "Domaine Marcel Deiss | \n", "
Domaine Schoffit 2012 Lieu-dit Harth Cuvée Caroline Gewurztraminer (Alsace) | \n", "France | \n", "Big, rich and off-dry, this is powered by inte... | \n", "Lieu-dit Harth Cuvée Caroline | \n", "90 | \n", "21.0 | \n", "Alsace | \n", "Alsace | \n", "NaN | \n", "Roger Voss | \n", "@vossroger | \n", "Gewürztraminer | \n", "Domaine Schoffit | \n", "
129971 rows × 12 columns
\n", "\n", " | country | \n", "description | \n", "designation | \n", "points | \n", "price | \n", "province | \n", "region_1 | \n", "region_2 | \n", "taster_name | \n", "taster_twitter_handle | \n", "title | \n", "variety | \n", "winery | \n", "
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | \n", "Italy | \n", "Aromas include tropical fruit, broom, brimston... | \n", "Vulkà Bianco | \n", "87 | \n", "NaN | \n", "Sicily & Sardinia | \n", "Etna | \n", "NaN | \n", "Kerin O’Keefe | \n", "@kerinokeefe | \n", "Nicosia 2013 Vulkà Bianco (Etna) | \n", "White Blend | \n", "Nicosia | \n", "
6 | \n", "Italy | \n", "Here's a bright, informal red that opens with ... | \n", "Belsito | \n", "87 | \n", "16.0 | \n", "Sicily & Sardinia | \n", "Vittoria | \n", "NaN | \n", "Kerin O’Keefe | \n", "@kerinokeefe | \n", "Terre di Giurfo 2013 Belsito Frappato (Vittoria) | \n", "Frappato | \n", "Terre di Giurfo | \n", "
... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "
129961 | \n", "Italy | \n", "Intense aromas of wild cherry, baking spice, t... | \n", "NaN | \n", "90 | \n", "30.0 | \n", "Sicily & Sardinia | \n", "Sicilia | \n", "NaN | \n", "Kerin O’Keefe | \n", "@kerinokeefe | \n", "COS 2013 Frappato (Sicilia) | \n", "Frappato | \n", "COS | \n", "
129962 | \n", "Italy | \n", "Blackberry, cassis, grilled herb and toasted a... | \n", "Sàgana Tenuta San Giacomo | \n", "90 | \n", "40.0 | \n", "Sicily & Sardinia | \n", "Sicilia | \n", "NaN | \n", "Kerin O’Keefe | \n", "@kerinokeefe | \n", "Cusumano 2012 Sàgana Tenuta San Giacomo Nero d... | \n", "Nero d'Avola | \n", "Cusumano | \n", "
19540 rows × 13 columns
\n", "\n", " | country | \n", "description | \n", "designation | \n", "points | \n", "price | \n", "province | \n", "region_1 | \n", "region_2 | \n", "taster_name | \n", "taster_twitter_handle | \n", "title | \n", "variety | \n", "winery | \n", "
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
120 | \n", "Italy | \n", "Slightly backward, particularly given the vint... | \n", "Bricco Rocche Prapó | \n", "92 | \n", "70.0 | \n", "Piedmont | \n", "Barolo | \n", "NaN | \n", "NaN | \n", "NaN | \n", "Ceretto 2003 Bricco Rocche Prapó (Barolo) | \n", "Nebbiolo | \n", "Ceretto | \n", "
130 | \n", "Italy | \n", "At the first it was quite muted and subdued, b... | \n", "Bricco Rocche Brunate | \n", "91 | \n", "70.0 | \n", "Piedmont | \n", "Barolo | \n", "NaN | \n", "NaN | \n", "NaN | \n", "Ceretto 2003 Bricco Rocche Brunate (Barolo) | \n", "Nebbiolo | \n", "Ceretto | \n", "
... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "
129961 | \n", "Italy | \n", "Intense aromas of wild cherry, baking spice, t... | \n", "NaN | \n", "90 | \n", "30.0 | \n", "Sicily & Sardinia | \n", "Sicilia | \n", "NaN | \n", "Kerin O’Keefe | \n", "@kerinokeefe | \n", "COS 2013 Frappato (Sicilia) | \n", "Frappato | \n", "COS | \n", "
129962 | \n", "Italy | \n", "Blackberry, cassis, grilled herb and toasted a... | \n", "Sàgana Tenuta San Giacomo | \n", "90 | \n", "40.0 | \n", "Sicily & Sardinia | \n", "Sicilia | \n", "NaN | \n", "Kerin O’Keefe | \n", "@kerinokeefe | \n", "Cusumano 2012 Sàgana Tenuta San Giacomo Nero d... | \n", "Nero d'Avola | \n", "Cusumano | \n", "
6648 rows × 13 columns
\n", "\n", " | country | \n", "description | \n", "designation | \n", "points | \n", "price | \n", "province | \n", "region_1 | \n", "region_2 | \n", "taster_name | \n", "taster_twitter_handle | \n", "title | \n", "variety | \n", "winery | \n", "
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | \n", "Italy | \n", "Aromas include tropical fruit, broom, brimston... | \n", "Vulkà Bianco | \n", "87 | \n", "NaN | \n", "Sicily & Sardinia | \n", "Etna | \n", "NaN | \n", "Kerin O’Keefe | \n", "@kerinokeefe | \n", "Nicosia 2013 Vulkà Bianco (Etna) | \n", "White Blend | \n", "Nicosia | \n", "
6 | \n", "Italy | \n", "Here's a bright, informal red that opens with ... | \n", "Belsito | \n", "87 | \n", "16.0 | \n", "Sicily & Sardinia | \n", "Vittoria | \n", "NaN | \n", "Kerin O’Keefe | \n", "@kerinokeefe | \n", "Terre di Giurfo 2013 Belsito Frappato (Vittoria) | \n", "Frappato | \n", "Terre di Giurfo | \n", "
... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "
129969 | \n", "France | \n", "A dry style of Pinot Gris, this is crisp with ... | \n", "NaN | \n", "90 | \n", "32.0 | \n", "Alsace | \n", "Alsace | \n", "NaN | \n", "Roger Voss | \n", "@vossroger | \n", "Domaine Marcel Deiss 2012 Pinot Gris (Alsace) | \n", "Pinot Gris | \n", "Domaine Marcel Deiss | \n", "
129970 | \n", "France | \n", "Big, rich and off-dry, this is powered by inte... | \n", "Lieu-dit Harth Cuvée Caroline | \n", "90 | \n", "21.0 | \n", "Alsace | \n", "Alsace | \n", "NaN | \n", "Roger Voss | \n", "@vossroger | \n", "Domaine Schoffit 2012 Lieu-dit Harth Cuvée Car... | \n", "Gewürztraminer | \n", "Domaine Schoffit | \n", "
61937 rows × 13 columns
\n", "\n", " | country | \n", "description | \n", "designation | \n", "points | \n", "price | \n", "province | \n", "region_1 | \n", "region_2 | \n", "taster_name | \n", "taster_twitter_handle | \n", "title | \n", "variety | \n", "winery | \n", "
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | \n", "Italy | \n", "Aromas include tropical fruit, broom, brimston... | \n", "Vulkà Bianco | \n", "87 | \n", "NaN | \n", "Sicily & Sardinia | \n", "Etna | \n", "NaN | \n", "Kerin O’Keefe | \n", "@kerinokeefe | \n", "Nicosia 2013 Vulkà Bianco (Etna) | \n", "White Blend | \n", "Nicosia | \n", "
6 | \n", "Italy | \n", "Here's a bright, informal red that opens with ... | \n", "Belsito | \n", "87 | \n", "16.0 | \n", "Sicily & Sardinia | \n", "Vittoria | \n", "NaN | \n", "Kerin O’Keefe | \n", "@kerinokeefe | \n", "Terre di Giurfo 2013 Belsito Frappato (Vittoria) | \n", "Frappato | \n", "Terre di Giurfo | \n", "
... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "
129969 | \n", "France | \n", "A dry style of Pinot Gris, this is crisp with ... | \n", "NaN | \n", "90 | \n", "32.0 | \n", "Alsace | \n", "Alsace | \n", "NaN | \n", "Roger Voss | \n", "@vossroger | \n", "Domaine Marcel Deiss 2012 Pinot Gris (Alsace) | \n", "Pinot Gris | \n", "Domaine Marcel Deiss | \n", "
129970 | \n", "France | \n", "Big, rich and off-dry, this is powered by inte... | \n", "Lieu-dit Harth Cuvée Caroline | \n", "90 | \n", "21.0 | \n", "Alsace | \n", "Alsace | \n", "NaN | \n", "Roger Voss | \n", "@vossroger | \n", "Domaine Schoffit 2012 Lieu-dit Harth Cuvée Car... | \n", "Gewürztraminer | \n", "Domaine Schoffit | \n", "
41633 rows × 13 columns
\n", "\n", " | country | \n", "description | \n", "designation | \n", "points | \n", "price | \n", "province | \n", "region_1 | \n", "region_2 | \n", "taster_name | \n", "taster_twitter_handle | \n", "title | \n", "variety | \n", "winery | \n", "
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | \n", "Portugal | \n", "This is ripe and fruity, a wine that is smooth... | \n", "Avidagos | \n", "87 | \n", "15.0 | \n", "Douro | \n", "NaN | \n", "NaN | \n", "Roger Voss | \n", "@vossroger | \n", "Quinta dos Avidagos 2011 Avidagos Red (Douro) | \n", "Portuguese Red | \n", "Quinta dos Avidagos | \n", "
2 | \n", "US | \n", "Tart and snappy, the flavors of lime flesh and... | \n", "NaN | \n", "87 | \n", "14.0 | \n", "Oregon | \n", "Willamette Valley | \n", "Willamette Valley | \n", "Paul Gregutt | \n", "@paulgwine | \n", "Rainstorm 2013 Pinot Gris (Willamette Valley) | \n", "Pinot Gris | \n", "Rainstorm | \n", "
... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "
129969 | \n", "France | \n", "A dry style of Pinot Gris, this is crisp with ... | \n", "NaN | \n", "90 | \n", "32.0 | \n", "Alsace | \n", "Alsace | \n", "NaN | \n", "Roger Voss | \n", "@vossroger | \n", "Domaine Marcel Deiss 2012 Pinot Gris (Alsace) | \n", "Pinot Gris | \n", "Domaine Marcel Deiss | \n", "
129970 | \n", "France | \n", "Big, rich and off-dry, this is powered by inte... | \n", "Lieu-dit Harth Cuvée Caroline | \n", "90 | \n", "21.0 | \n", "Alsace | \n", "Alsace | \n", "NaN | \n", "Roger Voss | \n", "@vossroger | \n", "Domaine Schoffit 2012 Lieu-dit Harth Cuvée Car... | \n", "Gewürztraminer | \n", "Domaine Schoffit | \n", "
120975 rows × 13 columns
\n", "