{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**This notebook is an exercise in the [Pandas](https://www.kaggle.com/learn/pandas) course. You can reference the tutorial at [this link](https://www.kaggle.com/residentmario/renaming-and-combining).**\n",
"\n",
"---\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Introduction\n",
"\n",
"Run the following cell to load your data and some utility functions."
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Setup complete.\n"
]
}
],
"source": [
"import pandas as pd\n",
"\n",
"reviews = pd.read_csv(\"../input/wine-reviews/winemag-data-130k-v2.csv\", index_col=0)\n",
"\n",
"from learntools.core import binder; binder.bind(globals())\n",
"from learntools.pandas.renaming_and_combining import *\n",
"print(\"Setup complete.\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Exercises\n",
"\n",
"View the first several lines of your data by running the cell below:"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"
\n",
"\n",
"
\n",
" \n",
" \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",
"
\n",
" \n",
" \n",
" \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",
"
\n",
" \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",
" 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",
" 3 | \n",
" US | \n",
" Pineapple rind, lemon pith and orange blossom ... | \n",
" Reserve Late Harvest | \n",
" 87 | \n",
" 13.0 | \n",
" Michigan | \n",
" Lake Michigan Shore | \n",
" NaN | \n",
" Alexander Peartree | \n",
" NaN | \n",
" St. Julian 2013 Reserve Late Harvest Riesling ... | \n",
" Riesling | \n",
" St. Julian | \n",
"
\n",
" \n",
" 4 | \n",
" US | \n",
" Much like the regular bottling from 2012, this... | \n",
" Vintner's Reserve Wild Child Block | \n",
" 87 | \n",
" 65.0 | \n",
" Oregon | \n",
" Willamette Valley | \n",
" Willamette Valley | \n",
" Paul Gregutt | \n",
" @paulgwine | \n",
" Sweet Cheeks 2012 Vintner's Reserve Wild Child... | \n",
" Pinot Noir | \n",
" Sweet Cheeks | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" country description \\\n",
"0 Italy Aromas include tropical fruit, broom, brimston... \n",
"1 Portugal This is ripe and fruity, a wine that is smooth... \n",
"2 US Tart and snappy, the flavors of lime flesh and... \n",
"3 US Pineapple rind, lemon pith and orange blossom ... \n",
"4 US Much like the regular bottling from 2012, this... \n",
"\n",
" designation points price province \\\n",
"0 Vulkà Bianco 87 NaN Sicily & Sardinia \n",
"1 Avidagos 87 15.0 Douro \n",
"2 NaN 87 14.0 Oregon \n",
"3 Reserve Late Harvest 87 13.0 Michigan \n",
"4 Vintner's Reserve Wild Child Block 87 65.0 Oregon \n",
"\n",
" region_1 region_2 taster_name \\\n",
"0 Etna NaN Kerin O’Keefe \n",
"1 NaN NaN Roger Voss \n",
"2 Willamette Valley Willamette Valley Paul Gregutt \n",
"3 Lake Michigan Shore NaN Alexander Peartree \n",
"4 Willamette Valley Willamette Valley Paul Gregutt \n",
"\n",
" taster_twitter_handle title \\\n",
"0 @kerinokeefe Nicosia 2013 Vulkà Bianco (Etna) \n",
"1 @vossroger Quinta dos Avidagos 2011 Avidagos Red (Douro) \n",
"2 @paulgwine Rainstorm 2013 Pinot Gris (Willamette Valley) \n",
"3 NaN St. Julian 2013 Reserve Late Harvest Riesling ... \n",
"4 @paulgwine Sweet Cheeks 2012 Vintner's Reserve Wild Child... \n",
"\n",
" variety winery \n",
"0 White Blend Nicosia \n",
"1 Portuguese Red Quinta dos Avidagos \n",
"2 Pinot Gris Rainstorm \n",
"3 Riesling St. Julian \n",
"4 Pinot Noir Sweet Cheeks "
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"reviews.head()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 1.\n",
"`region_1` and `region_2` are pretty uninformative names for locale columns in the dataset. Create a copy of `reviews` with these columns renamed to `region` and `locale`, respectively."
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"data": {
"application/javascript": [
"parent.postMessage({\"jupyterEvent\": \"custom.exercise_interaction\", \"data\": {\"outcomeType\": 1, \"valueTowardsCompletion\": 0.25, \"interactionType\": 1, \"questionType\": 1, \"questionId\": \"1_RenameCols\", \"learnToolsVersion\": \"0.3.4\", \"failureMessage\": \"\", \"exceptionClass\": \"\", \"trace\": \"\"}}, \"*\")"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/markdown": [
"Correct"
],
"text/plain": [
"Correct"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"# Your code here\n",
"renamed = renamed.rename(columns={'region_1': 'region', 'region_2': 'locale'})\n",
"\n",
"# Check your answer\n",
"q1.check()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#q1.hint()\n",
"#q1.solution()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 2.\n",
"Set the index name in the dataset to `wines`."
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [
{
"data": {
"application/javascript": [
"parent.postMessage({\"jupyterEvent\": \"custom.exercise_interaction\", \"data\": {\"outcomeType\": 1, \"valueTowardsCompletion\": 0.25, \"interactionType\": 1, \"questionType\": 1, \"questionId\": \"2_RenameIndex\", \"learnToolsVersion\": \"0.3.4\", \"failureMessage\": \"\", \"exceptionClass\": \"\", \"trace\": \"\"}}, \"*\")"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/markdown": [
"Correct"
],
"text/plain": [
"Correct"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"reindexed = reviews.rename_axis('wines')\n",
"\n",
"# Check your answer\n",
"q2.check()"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [
{
"data": {
"application/javascript": [
"parent.postMessage({\"jupyterEvent\": \"custom.exercise_interaction\", \"data\": {\"interactionType\": 2, \"questionType\": 1, \"questionId\": \"2_RenameIndex\", \"learnToolsVersion\": \"0.3.4\", \"valueTowardsCompletion\": 0.0, \"failureMessage\": \"\", \"exceptionClass\": \"\", \"trace\": \"\", \"outcomeType\": 4}}, \"*\")"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/markdown": [
"Hint: Use the `rename_axis()` method."
],
"text/plain": [
"Hint: Use the `rename_axis()` method."
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"q2.hint()\n",
"#q2.solution()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 3.\n",
"The [Things on Reddit](https://www.kaggle.com/residentmario/things-on-reddit/data) dataset includes product links from a selection of top-ranked forums (\"subreddits\") on reddit.com. Run the cell below to load a dataframe of products mentioned on the */r/gaming* subreddit and another dataframe for products mentioned on the *r//movies* subreddit."
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {},
"outputs": [],
"source": [
"gaming_products = pd.read_csv(\"../input/things-on-reddit/top-things/top-things/reddits/g/gaming.csv\")\n",
"gaming_products['subreddit'] = \"r/gaming\"\n",
"movie_products = pd.read_csv(\"../input/things-on-reddit/top-things/top-things/reddits/m/movies.csv\")\n",
"movie_products['subreddit'] = \"r/movies\""
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" name | \n",
" category | \n",
" amazon_link | \n",
" total_mentions | \n",
" subreddit_mentions | \n",
" subreddit | \n",
"
\n",
" \n",
" \n",
" \n",
" 0 | \n",
" BOOMco Halo Covenant Needler Blaster | \n",
" Toys & Games | \n",
" https://www.amazon.com/BOOMco-Halo-Covenant-Ne... | \n",
" 4.0 | \n",
" 4 | \n",
" r/gaming | \n",
"
\n",
" \n",
" 1 | \n",
" Raspberry PI 3 Model B 1.2GHz 64-bit quad-core... | \n",
" Electronics | \n",
" https://www.amazon.com/Raspberry-Model-A1-2GHz... | \n",
" 19.0 | \n",
" 3 | \n",
" r/gaming | \n",
"
\n",
" \n",
" 2 | \n",
" CanaKit 5V 2.5A Raspberry Pi 3 Power Supply / ... | \n",
" Electronics | \n",
" https://www.amazon.com/CanaKit-Raspberry-Suppl... | \n",
" 7.0 | \n",
" 3 | \n",
" r/gaming | \n",
"
\n",
" \n",
" 3 | \n",
" Panasonic K-KJ17MCA4BA Advanced Individual Cel... | \n",
" Electronics | \n",
" https://www.amazon.com/Panasonic-Advanced-Indi... | \n",
" 29.0 | \n",
" 2 | \n",
" r/gaming | \n",
"
\n",
" \n",
" 4 | \n",
" Mayflash GameCube Controller Adapter for Wii U... | \n",
" Electronics | \n",
" https://www.amazon.com/GameCube-Controller-Ada... | \n",
" 24.0 | \n",
" 2 | \n",
" r/gaming | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" name category \\\n",
"0 BOOMco Halo Covenant Needler Blaster Toys & Games \n",
"1 Raspberry PI 3 Model B 1.2GHz 64-bit quad-core... Electronics \n",
"2 CanaKit 5V 2.5A Raspberry Pi 3 Power Supply / ... Electronics \n",
"3 Panasonic K-KJ17MCA4BA Advanced Individual Cel... Electronics \n",
"4 Mayflash GameCube Controller Adapter for Wii U... Electronics \n",
"\n",
" amazon_link total_mentions \\\n",
"0 https://www.amazon.com/BOOMco-Halo-Covenant-Ne... 4.0 \n",
"1 https://www.amazon.com/Raspberry-Model-A1-2GHz... 19.0 \n",
"2 https://www.amazon.com/CanaKit-Raspberry-Suppl... 7.0 \n",
"3 https://www.amazon.com/Panasonic-Advanced-Indi... 29.0 \n",
"4 https://www.amazon.com/GameCube-Controller-Ada... 24.0 \n",
"\n",
" subreddit_mentions subreddit \n",
"0 4 r/gaming \n",
"1 3 r/gaming \n",
"2 3 r/gaming \n",
"3 2 r/gaming \n",
"4 2 r/gaming "
]
},
"execution_count": 19,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"gaming_products.head()"
]
},
{
"cell_type": "code",
"execution_count": 20,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" name | \n",
" category | \n",
" amazon_link | \n",
" total_mentions | \n",
" subreddit_mentions | \n",
" subreddit | \n",
"
\n",
" \n",
" \n",
" \n",
" 0 | \n",
" Marvel Cinematic Universe: Phase One - Avenger... | \n",
" Movies & TV | \n",
" https://www.amazon.com/Marvel-Cinematic-Univer... | \n",
" 4.0 | \n",
" 3 | \n",
" r/movies | \n",
"
\n",
" \n",
" 1 | \n",
" On Stranger Tides | \n",
" Books | \n",
" https://www.amazon.com/Stranger-Tides-Tim-Powe... | \n",
" 3.0 | \n",
" 3 | \n",
" r/movies | \n",
"
\n",
" \n",
" 2 | \n",
" Superintelligence: Paths, Dangers, Strategies | \n",
" Books | \n",
" https://www.amazon.com/Superintelligence-Dange... | \n",
" 7.0 | \n",
" 2 | \n",
" r/movies | \n",
"
\n",
" \n",
" 3 | \n",
" The Secret History of Star Wars | \n",
" Books | \n",
" https://www.amazon.com/Secret-History-Star-War... | \n",
" 4.0 | \n",
" 2 | \n",
" r/movies | \n",
"
\n",
" \n",
" 4 | \n",
" 2D Glasses 4 Pack - Turns 3D movies back into ... | \n",
" Electronics | \n",
" https://www.amazon.com/gp/product/B00K9E7GCC | \n",
" 3.0 | \n",
" 2 | \n",
" r/movies | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" name category \\\n",
"0 Marvel Cinematic Universe: Phase One - Avenger... Movies & TV \n",
"1 On Stranger Tides Books \n",
"2 Superintelligence: Paths, Dangers, Strategies Books \n",
"3 The Secret History of Star Wars Books \n",
"4 2D Glasses 4 Pack - Turns 3D movies back into ... Electronics \n",
"\n",
" amazon_link total_mentions \\\n",
"0 https://www.amazon.com/Marvel-Cinematic-Univer... 4.0 \n",
"1 https://www.amazon.com/Stranger-Tides-Tim-Powe... 3.0 \n",
"2 https://www.amazon.com/Superintelligence-Dange... 7.0 \n",
"3 https://www.amazon.com/Secret-History-Star-War... 4.0 \n",
"4 https://www.amazon.com/gp/product/B00K9E7GCC 3.0 \n",
"\n",
" subreddit_mentions subreddit \n",
"0 3 r/movies \n",
"1 3 r/movies \n",
"2 2 r/movies \n",
"3 2 r/movies \n",
"4 2 r/movies "
]
},
"execution_count": 20,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"movie_products.head()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Create a `DataFrame` of products mentioned on *either* subreddit."
]
},
{
"cell_type": "code",
"execution_count": 22,
"metadata": {},
"outputs": [
{
"data": {
"application/javascript": [
"parent.postMessage({\"jupyterEvent\": \"custom.exercise_interaction\", \"data\": {\"outcomeType\": 1, \"valueTowardsCompletion\": 0.25, \"interactionType\": 1, \"questionType\": 2, \"questionId\": \"3_ConcatReddit\", \"learnToolsVersion\": \"0.3.4\", \"failureMessage\": \"\", \"exceptionClass\": \"\", \"trace\": \"\"}}, \"*\")"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/markdown": [
"Correct"
],
"text/plain": [
"Correct"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"combined_products = pd.concat([gaming_products, movie_products])\n",
"\n",
"# Check your answer\n",
"q3.check()"
]
},
{
"cell_type": "code",
"execution_count": 23,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" name | \n",
" category | \n",
" amazon_link | \n",
" total_mentions | \n",
" subreddit_mentions | \n",
" subreddit | \n",
"
\n",
" \n",
" \n",
" \n",
" 0 | \n",
" BOOMco Halo Covenant Needler Blaster | \n",
" Toys & Games | \n",
" https://www.amazon.com/BOOMco-Halo-Covenant-Ne... | \n",
" 4.0 | \n",
" 4 | \n",
" r/gaming | \n",
"
\n",
" \n",
" 1 | \n",
" Raspberry PI 3 Model B 1.2GHz 64-bit quad-core... | \n",
" Electronics | \n",
" https://www.amazon.com/Raspberry-Model-A1-2GHz... | \n",
" 19.0 | \n",
" 3 | \n",
" r/gaming | \n",
"
\n",
" \n",
" 2 | \n",
" CanaKit 5V 2.5A Raspberry Pi 3 Power Supply / ... | \n",
" Electronics | \n",
" https://www.amazon.com/CanaKit-Raspberry-Suppl... | \n",
" 7.0 | \n",
" 3 | \n",
" r/gaming | \n",
"
\n",
" \n",
" 3 | \n",
" Panasonic K-KJ17MCA4BA Advanced Individual Cel... | \n",
" Electronics | \n",
" https://www.amazon.com/Panasonic-Advanced-Indi... | \n",
" 29.0 | \n",
" 2 | \n",
" r/gaming | \n",
"
\n",
" \n",
" 4 | \n",
" Mayflash GameCube Controller Adapter for Wii U... | \n",
" Electronics | \n",
" https://www.amazon.com/GameCube-Controller-Ada... | \n",
" 24.0 | \n",
" 2 | \n",
" r/gaming | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" name category \\\n",
"0 BOOMco Halo Covenant Needler Blaster Toys & Games \n",
"1 Raspberry PI 3 Model B 1.2GHz 64-bit quad-core... Electronics \n",
"2 CanaKit 5V 2.5A Raspberry Pi 3 Power Supply / ... Electronics \n",
"3 Panasonic K-KJ17MCA4BA Advanced Individual Cel... Electronics \n",
"4 Mayflash GameCube Controller Adapter for Wii U... Electronics \n",
"\n",
" amazon_link total_mentions \\\n",
"0 https://www.amazon.com/BOOMco-Halo-Covenant-Ne... 4.0 \n",
"1 https://www.amazon.com/Raspberry-Model-A1-2GHz... 19.0 \n",
"2 https://www.amazon.com/CanaKit-Raspberry-Suppl... 7.0 \n",
"3 https://www.amazon.com/Panasonic-Advanced-Indi... 29.0 \n",
"4 https://www.amazon.com/GameCube-Controller-Ada... 24.0 \n",
"\n",
" subreddit_mentions subreddit \n",
"0 4 r/gaming \n",
"1 3 r/gaming \n",
"2 3 r/gaming \n",
"3 2 r/gaming \n",
"4 2 r/gaming "
]
},
"execution_count": 23,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"combined_products.head()"
]
},
{
"cell_type": "code",
"execution_count": 24,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" name | \n",
" category | \n",
" amazon_link | \n",
" total_mentions | \n",
" subreddit_mentions | \n",
" subreddit | \n",
"
\n",
" \n",
" \n",
" \n",
" 298 | \n",
" Welcome to Night Vale CD: A Novel | \n",
" Books | \n",
" https://www.amazon.com/Welcome-Night-Vale-CD-N... | \n",
" 1.0 | \n",
" 1 | \n",
" r/movies | \n",
"
\n",
" \n",
" 299 | \n",
" Ran (StudioCanal Collection) [Blu-ray] | \n",
" Movies & TV | \n",
" https://www.amazon.com/StudioCanal-Collection-... | \n",
" 1.0 | \n",
" 1 | \n",
" r/movies | \n",
"
\n",
" \n",
" 300 | \n",
" The Art of John Alvin | \n",
" Books | \n",
" https://www.amazon.com/Art-John-Alvin-Andrea/d... | \n",
" 1.0 | \n",
" 1 | \n",
" r/movies | \n",
"
\n",
" \n",
" 301 | \n",
" Apocalypto [Blu-ray] | \n",
" Movies & TV | \n",
" https://www.amazon.com/Apocalypto-Blu-ray-Rudy... | \n",
" 1.0 | \n",
" 1 | \n",
" r/movies | \n",
"
\n",
" \n",
" 302 | \n",
" Cinelinx: A Card Game for People Who Love Movi... | \n",
" Toys & Games | \n",
" https://www.amazon.com/Cinelinx-Card-Game-Peop... | \n",
" 1.0 | \n",
" 1 | \n",
" r/movies | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" name category \\\n",
"298 Welcome to Night Vale CD: A Novel Books \n",
"299 Ran (StudioCanal Collection) [Blu-ray] Movies & TV \n",
"300 The Art of John Alvin Books \n",
"301 Apocalypto [Blu-ray] Movies & TV \n",
"302 Cinelinx: A Card Game for People Who Love Movi... Toys & Games \n",
"\n",
" amazon_link total_mentions \\\n",
"298 https://www.amazon.com/Welcome-Night-Vale-CD-N... 1.0 \n",
"299 https://www.amazon.com/StudioCanal-Collection-... 1.0 \n",
"300 https://www.amazon.com/Art-John-Alvin-Andrea/d... 1.0 \n",
"301 https://www.amazon.com/Apocalypto-Blu-ray-Rudy... 1.0 \n",
"302 https://www.amazon.com/Cinelinx-Card-Game-Peop... 1.0 \n",
"\n",
" subreddit_mentions subreddit \n",
"298 1 r/movies \n",
"299 1 r/movies \n",
"300 1 r/movies \n",
"301 1 r/movies \n",
"302 1 r/movies "
]
},
"execution_count": 24,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"combined_products.tail()"
]
},
{
"cell_type": "code",
"execution_count": 26,
"metadata": {},
"outputs": [],
"source": [
"#q3.hint()\n",
"#q3.solution()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 4.\n",
"The [Powerlifting Database](https://www.kaggle.com/open-powerlifting/powerlifting-database) dataset on Kaggle includes one CSV table for powerlifting meets and a separate one for powerlifting competitors. Run the cell below to load these datasets into dataframes:"
]
},
{
"cell_type": "code",
"execution_count": 27,
"metadata": {},
"outputs": [],
"source": [
"powerlifting_meets = pd.read_csv(\"../input/powerlifting-database/meets.csv\")\n",
"powerlifting_competitors = pd.read_csv(\"../input/powerlifting-database/openpowerlifting.csv\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Both tables include references to a `MeetID`, a unique key for each meet (competition) included in the database. Using this, generate a dataset combining the two tables into one."
]
},
{
"cell_type": "code",
"execution_count": 28,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" MeetID | \n",
" MeetPath | \n",
" Federation | \n",
" Date | \n",
" MeetCountry | \n",
" MeetState | \n",
" MeetTown | \n",
" MeetName | \n",
"
\n",
" \n",
" \n",
" \n",
" 0 | \n",
" 0 | \n",
" 365strong/1601 | \n",
" 365Strong | \n",
" 2016-10-29 | \n",
" USA | \n",
" NC | \n",
" Charlotte | \n",
" 2016 Junior & Senior National Powerlifting Cha... | \n",
"
\n",
" \n",
" 1 | \n",
" 1 | \n",
" 365strong/1602 | \n",
" 365Strong | \n",
" 2016-11-19 | \n",
" USA | \n",
" MO | \n",
" Ozark | \n",
" Thanksgiving Powerlifting Classic | \n",
"
\n",
" \n",
" 2 | \n",
" 2 | \n",
" 365strong/1603 | \n",
" 365Strong | \n",
" 2016-07-09 | \n",
" USA | \n",
" NC | \n",
" Charlotte | \n",
" Charlotte Europa Games | \n",
"
\n",
" \n",
" 3 | \n",
" 3 | \n",
" 365strong/1604 | \n",
" 365Strong | \n",
" 2016-06-11 | \n",
" USA | \n",
" SC | \n",
" Rock Hill | \n",
" Carolina Cup Push Pull Challenge | \n",
"
\n",
" \n",
" 4 | \n",
" 4 | \n",
" 365strong/1605 | \n",
" 365Strong | \n",
" 2016-04-10 | \n",
" USA | \n",
" SC | \n",
" Rock Hill | \n",
" Eastern USA Challenge | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" MeetID MeetPath Federation Date MeetCountry MeetState \\\n",
"0 0 365strong/1601 365Strong 2016-10-29 USA NC \n",
"1 1 365strong/1602 365Strong 2016-11-19 USA MO \n",
"2 2 365strong/1603 365Strong 2016-07-09 USA NC \n",
"3 3 365strong/1604 365Strong 2016-06-11 USA SC \n",
"4 4 365strong/1605 365Strong 2016-04-10 USA SC \n",
"\n",
" MeetTown MeetName \n",
"0 Charlotte 2016 Junior & Senior National Powerlifting Cha... \n",
"1 Ozark Thanksgiving Powerlifting Classic \n",
"2 Charlotte Charlotte Europa Games \n",
"3 Rock Hill Carolina Cup Push Pull Challenge \n",
"4 Rock Hill Eastern USA Challenge "
]
},
"execution_count": 28,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"powerlifting_meets.head()"
]
},
{
"cell_type": "code",
"execution_count": 29,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" MeetID | \n",
" Name | \n",
" Sex | \n",
" Equipment | \n",
" Age | \n",
" Division | \n",
" BodyweightKg | \n",
" WeightClassKg | \n",
" Squat4Kg | \n",
" BestSquatKg | \n",
" Bench4Kg | \n",
" BestBenchKg | \n",
" Deadlift4Kg | \n",
" BestDeadliftKg | \n",
" TotalKg | \n",
" Place | \n",
" Wilks | \n",
"
\n",
" \n",
" \n",
" \n",
" 0 | \n",
" 0 | \n",
" Angie Belk Terry | \n",
" F | \n",
" Wraps | \n",
" 47.0 | \n",
" Mst 45-49 | \n",
" 59.60 | \n",
" 60 | \n",
" NaN | \n",
" 47.63 | \n",
" NaN | \n",
" 20.41 | \n",
" NaN | \n",
" 70.31 | \n",
" 138.35 | \n",
" 1 | \n",
" 155.05 | \n",
"
\n",
" \n",
" 1 | \n",
" 0 | \n",
" Dawn Bogart | \n",
" F | \n",
" Single-ply | \n",
" 42.0 | \n",
" Mst 40-44 | \n",
" 58.51 | \n",
" 60 | \n",
" NaN | \n",
" 142.88 | \n",
" NaN | \n",
" 95.25 | \n",
" NaN | \n",
" 163.29 | \n",
" 401.42 | \n",
" 1 | \n",
" 456.38 | \n",
"
\n",
" \n",
" 2 | \n",
" 0 | \n",
" Dawn Bogart | \n",
" F | \n",
" Single-ply | \n",
" 42.0 | \n",
" Open Senior | \n",
" 58.51 | \n",
" 60 | \n",
" NaN | \n",
" 142.88 | \n",
" NaN | \n",
" 95.25 | \n",
" NaN | \n",
" 163.29 | \n",
" 401.42 | \n",
" 1 | \n",
" 456.38 | \n",
"
\n",
" \n",
" 3 | \n",
" 0 | \n",
" Dawn Bogart | \n",
" F | \n",
" Raw | \n",
" 42.0 | \n",
" Open Senior | \n",
" 58.51 | \n",
" 60 | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" 95.25 | \n",
" NaN | \n",
" NaN | \n",
" 95.25 | \n",
" 1 | \n",
" 108.29 | \n",
"
\n",
" \n",
" 4 | \n",
" 0 | \n",
" Destiny Dula | \n",
" F | \n",
" Raw | \n",
" 18.0 | \n",
" Teen 18-19 | \n",
" 63.68 | \n",
" 67.5 | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" 31.75 | \n",
" NaN | \n",
" 90.72 | \n",
" 122.47 | \n",
" 1 | \n",
" 130.47 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" MeetID Name Sex Equipment Age Division BodyweightKg \\\n",
"0 0 Angie Belk Terry F Wraps 47.0 Mst 45-49 59.60 \n",
"1 0 Dawn Bogart F Single-ply 42.0 Mst 40-44 58.51 \n",
"2 0 Dawn Bogart F Single-ply 42.0 Open Senior 58.51 \n",
"3 0 Dawn Bogart F Raw 42.0 Open Senior 58.51 \n",
"4 0 Destiny Dula F Raw 18.0 Teen 18-19 63.68 \n",
"\n",
" WeightClassKg Squat4Kg BestSquatKg Bench4Kg BestBenchKg Deadlift4Kg \\\n",
"0 60 NaN 47.63 NaN 20.41 NaN \n",
"1 60 NaN 142.88 NaN 95.25 NaN \n",
"2 60 NaN 142.88 NaN 95.25 NaN \n",
"3 60 NaN NaN NaN 95.25 NaN \n",
"4 67.5 NaN NaN NaN 31.75 NaN \n",
"\n",
" BestDeadliftKg TotalKg Place Wilks \n",
"0 70.31 138.35 1 155.05 \n",
"1 163.29 401.42 1 456.38 \n",
"2 163.29 401.42 1 456.38 \n",
"3 NaN 95.25 1 108.29 \n",
"4 90.72 122.47 1 130.47 "
]
},
"execution_count": 29,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"powerlifting_competitors.head()"
]
},
{
"cell_type": "code",
"execution_count": 40,
"metadata": {},
"outputs": [
{
"data": {
"application/javascript": [
"parent.postMessage({\"jupyterEvent\": \"custom.exercise_interaction\", \"data\": {\"outcomeType\": 1, \"valueTowardsCompletion\": 0.25, \"interactionType\": 1, \"questionType\": 2, \"questionId\": \"4_JoinLifting\", \"learnToolsVersion\": \"0.3.4\", \"failureMessage\": \"\", \"exceptionClass\": \"\", \"trace\": \"\"}}, \"*\")"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/markdown": [
"Correct"
],
"text/plain": [
"Correct"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"meets = powerlifting_meets.set_index('MeetID')\n",
"competitors = powerlifting_competitors.set_index('MeetID')\n",
"powerlifting_combined = meets.join(competitors)\n",
"\n",
"# Check your answer\n",
"q4.check()"
]
},
{
"cell_type": "code",
"execution_count": 39,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Index(['MeetPath', 'Federation', 'Date', 'MeetCountry', 'MeetState',\n",
" 'MeetTown', 'MeetName', 'Name', 'Sex', 'Equipment', 'Age', 'Division',\n",
" 'BodyweightKg', 'WeightClassKg', 'Squat4Kg', 'BestSquatKg', 'Bench4Kg',\n",
" 'BestBenchKg', 'Deadlift4Kg', 'BestDeadliftKg', 'TotalKg', 'Place',\n",
" 'Wilks'],\n",
" dtype='object')"
]
},
"execution_count": 39,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"powerlifting_combined.columns"
]
},
{
"cell_type": "code",
"execution_count": 41,
"metadata": {},
"outputs": [
{
"data": {
"application/javascript": [
"parent.postMessage({\"jupyterEvent\": \"custom.exercise_interaction\", \"data\": {\"interactionType\": 3, \"questionType\": 2, \"questionId\": \"4_JoinLifting\", \"learnToolsVersion\": \"0.3.4\", \"valueTowardsCompletion\": 0.0, \"failureMessage\": \"\", \"exceptionClass\": \"\", \"trace\": \"\", \"outcomeType\": 4}}, \"*\")"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/markdown": [
"Solution: \n",
"```python\n",
"powerlifting_combined = powerlifting_meets.set_index(\"MeetID\").join(powerlifting_competitors.set_index(\"MeetID\"))\n",
"```"
],
"text/plain": [
"Solution: \n",
"```python\n",
"powerlifting_combined = powerlifting_meets.set_index(\"MeetID\").join(powerlifting_competitors.set_index(\"MeetID\"))\n",
"```"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"#q4.hint()\n",
"q4.solution()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Congratulations!\n",
"\n",
"You've finished the Pandas micro-course. Many data scientists feel efficiency with Pandas is the most useful and practical skill they have, because it allows you to progress quickly in any project you have.\n",
"\n",
"If you'd like to apply your new skills to examining geospatial data, you're encouraged to check out our **[Geospatial Analysis](https://www.kaggle.com/learn/geospatial-analysis)** micro-course.\n",
"\n",
"You can also take advantage of your Pandas skills by entering a **[Kaggle Competition](https://www.kaggle.com/competitions)** or by answering a question you find interesting using **[Kaggle Datasets](https://www.kaggle.com/datasets)**."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"---\n",
"\n",
"\n",
"\n",
"\n",
"*Have questions or comments? Visit the [Learn Discussion forum](https://www.kaggle.com/learn-forum/161299) to chat with other Learners.*"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"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.6"
}
},
"nbformat": 4,
"nbformat_minor": 4
}