Run the following cell to load your data and some utility functions.
import pandas as pd
reviews = pd.read_csv("../input/wine-reviews/winemag-data-130k-v2.csv", index_col=0)
from learntools.core import binder; binder.bind(globals())
from learntools.pandas.renaming_and_combining import *
print("Setup complete.")
Setup complete.
View the first several lines of your data by running the cell below:
reviews.head()
country | description | designation | points | price | province | region_1 | region_2 | taster_name | taster_twitter_handle | title | variety | winery | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | Italy | Aromas include tropical fruit, broom, brimston... | Vulkà Bianco | 87 | NaN | Sicily & Sardinia | Etna | NaN | Kerin O’Keefe | @kerinokeefe | Nicosia 2013 Vulkà Bianco (Etna) | White Blend | Nicosia |
1 | Portugal | This is ripe and fruity, a wine that is smooth... | Avidagos | 87 | 15.0 | Douro | NaN | NaN | Roger Voss | @vossroger | Quinta dos Avidagos 2011 Avidagos Red (Douro) | Portuguese Red | Quinta dos Avidagos |
2 | US | Tart and snappy, the flavors of lime flesh and... | NaN | 87 | 14.0 | Oregon | Willamette Valley | Willamette Valley | Paul Gregutt | @paulgwine | Rainstorm 2013 Pinot Gris (Willamette Valley) | Pinot Gris | Rainstorm |
3 | US | Pineapple rind, lemon pith and orange blossom ... | Reserve Late Harvest | 87 | 13.0 | Michigan | Lake Michigan Shore | NaN | Alexander Peartree | NaN | St. Julian 2013 Reserve Late Harvest Riesling ... | Riesling | St. Julian |
4 | US | Much like the regular bottling from 2012, this... | Vintner's Reserve Wild Child Block | 87 | 65.0 | Oregon | Willamette Valley | Willamette Valley | Paul Gregutt | @paulgwine | Sweet Cheeks 2012 Vintner's Reserve Wild Child... | Pinot Noir | Sweet Cheeks |
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.
# Your code here
renamed = renamed.rename(columns={'region_1': 'region', 'region_2': 'locale'})
# Check your answer
q1.check()
Correct
#q1.hint()
#q1.solution()
Set the index name in the dataset to wines
.
reindexed = reviews.rename_axis('wines')
# Check your answer
q2.check()
Correct
q2.hint()
#q2.solution()
Hint: Use the rename_axis()
method.
The Things on Reddit 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.
gaming_products = pd.read_csv("../input/things-on-reddit/top-things/top-things/reddits/g/gaming.csv")
gaming_products['subreddit'] = "r/gaming"
movie_products = pd.read_csv("../input/things-on-reddit/top-things/top-things/reddits/m/movies.csv")
movie_products['subreddit'] = "r/movies"
gaming_products.head()
name | category | amazon_link | total_mentions | subreddit_mentions | subreddit | |
---|---|---|---|---|---|---|
0 | BOOMco Halo Covenant Needler Blaster | Toys & Games | https://www.amazon.com/BOOMco-Halo-Covenant-Ne... | 4.0 | 4 | r/gaming |
1 | Raspberry PI 3 Model B 1.2GHz 64-bit quad-core... | Electronics | https://www.amazon.com/Raspberry-Model-A1-2GHz... | 19.0 | 3 | r/gaming |
2 | CanaKit 5V 2.5A Raspberry Pi 3 Power Supply / ... | Electronics | https://www.amazon.com/CanaKit-Raspberry-Suppl... | 7.0 | 3 | r/gaming |
3 | Panasonic K-KJ17MCA4BA Advanced Individual Cel... | Electronics | https://www.amazon.com/Panasonic-Advanced-Indi... | 29.0 | 2 | r/gaming |
4 | Mayflash GameCube Controller Adapter for Wii U... | Electronics | https://www.amazon.com/GameCube-Controller-Ada... | 24.0 | 2 | r/gaming |
movie_products.head()
name | category | amazon_link | total_mentions | subreddit_mentions | subreddit | |
---|---|---|---|---|---|---|
0 | Marvel Cinematic Universe: Phase One - Avenger... | Movies & TV | https://www.amazon.com/Marvel-Cinematic-Univer... | 4.0 | 3 | r/movies |
1 | On Stranger Tides | Books | https://www.amazon.com/Stranger-Tides-Tim-Powe... | 3.0 | 3 | r/movies |
2 | Superintelligence: Paths, Dangers, Strategies | Books | https://www.amazon.com/Superintelligence-Dange... | 7.0 | 2 | r/movies |
3 | The Secret History of Star Wars | Books | https://www.amazon.com/Secret-History-Star-War... | 4.0 | 2 | r/movies |
4 | 2D Glasses 4 Pack - Turns 3D movies back into ... | Electronics | https://www.amazon.com/gp/product/B00K9E7GCC | 3.0 | 2 | r/movies |
Create a DataFrame
of products mentioned on either subreddit.
combined_products = pd.concat([gaming_products, movie_products])
# Check your answer
q3.check()
Correct
combined_products.head()
name | category | amazon_link | total_mentions | subreddit_mentions | subreddit | |
---|---|---|---|---|---|---|
0 | BOOMco Halo Covenant Needler Blaster | Toys & Games | https://www.amazon.com/BOOMco-Halo-Covenant-Ne... | 4.0 | 4 | r/gaming |
1 | Raspberry PI 3 Model B 1.2GHz 64-bit quad-core... | Electronics | https://www.amazon.com/Raspberry-Model-A1-2GHz... | 19.0 | 3 | r/gaming |
2 | CanaKit 5V 2.5A Raspberry Pi 3 Power Supply / ... | Electronics | https://www.amazon.com/CanaKit-Raspberry-Suppl... | 7.0 | 3 | r/gaming |
3 | Panasonic K-KJ17MCA4BA Advanced Individual Cel... | Electronics | https://www.amazon.com/Panasonic-Advanced-Indi... | 29.0 | 2 | r/gaming |
4 | Mayflash GameCube Controller Adapter for Wii U... | Electronics | https://www.amazon.com/GameCube-Controller-Ada... | 24.0 | 2 | r/gaming |
combined_products.tail()
name | category | amazon_link | total_mentions | subreddit_mentions | subreddit | |
---|---|---|---|---|---|---|
298 | Welcome to Night Vale CD: A Novel | Books | https://www.amazon.com/Welcome-Night-Vale-CD-N... | 1.0 | 1 | r/movies |
299 | Ran (StudioCanal Collection) [Blu-ray] | Movies & TV | https://www.amazon.com/StudioCanal-Collection-... | 1.0 | 1 | r/movies |
300 | The Art of John Alvin | Books | https://www.amazon.com/Art-John-Alvin-Andrea/d... | 1.0 | 1 | r/movies |
301 | Apocalypto [Blu-ray] | Movies & TV | https://www.amazon.com/Apocalypto-Blu-ray-Rudy... | 1.0 | 1 | r/movies |
302 | Cinelinx: A Card Game for People Who Love Movi... | Toys & Games | https://www.amazon.com/Cinelinx-Card-Game-Peop... | 1.0 | 1 | r/movies |
#q3.hint()
#q3.solution()
The 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:
powerlifting_meets = pd.read_csv("../input/powerlifting-database/meets.csv")
powerlifting_competitors = pd.read_csv("../input/powerlifting-database/openpowerlifting.csv")
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.
powerlifting_meets.head()
MeetID | MeetPath | Federation | Date | MeetCountry | MeetState | MeetTown | MeetName | |
---|---|---|---|---|---|---|---|---|
0 | 0 | 365strong/1601 | 365Strong | 2016-10-29 | USA | NC | Charlotte | 2016 Junior & Senior National Powerlifting Cha... |
1 | 1 | 365strong/1602 | 365Strong | 2016-11-19 | USA | MO | Ozark | Thanksgiving Powerlifting Classic |
2 | 2 | 365strong/1603 | 365Strong | 2016-07-09 | USA | NC | Charlotte | Charlotte Europa Games |
3 | 3 | 365strong/1604 | 365Strong | 2016-06-11 | USA | SC | Rock Hill | Carolina Cup Push Pull Challenge |
4 | 4 | 365strong/1605 | 365Strong | 2016-04-10 | USA | SC | Rock Hill | Eastern USA Challenge |
powerlifting_competitors.head()
MeetID | Name | Sex | Equipment | Age | Division | BodyweightKg | WeightClassKg | Squat4Kg | BestSquatKg | Bench4Kg | BestBenchKg | Deadlift4Kg | BestDeadliftKg | TotalKg | Place | Wilks | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 0 | Angie Belk Terry | F | Wraps | 47.0 | Mst 45-49 | 59.60 | 60 | NaN | 47.63 | NaN | 20.41 | NaN | 70.31 | 138.35 | 1 | 155.05 |
1 | 0 | Dawn Bogart | F | Single-ply | 42.0 | Mst 40-44 | 58.51 | 60 | NaN | 142.88 | NaN | 95.25 | NaN | 163.29 | 401.42 | 1 | 456.38 |
2 | 0 | Dawn Bogart | F | Single-ply | 42.0 | Open Senior | 58.51 | 60 | NaN | 142.88 | NaN | 95.25 | NaN | 163.29 | 401.42 | 1 | 456.38 |
3 | 0 | Dawn Bogart | F | Raw | 42.0 | Open Senior | 58.51 | 60 | NaN | NaN | NaN | 95.25 | NaN | NaN | 95.25 | 1 | 108.29 |
4 | 0 | Destiny Dula | F | Raw | 18.0 | Teen 18-19 | 63.68 | 67.5 | NaN | NaN | NaN | 31.75 | NaN | 90.72 | 122.47 | 1 | 130.47 |
meets = powerlifting_meets.set_index('MeetID')
competitors = powerlifting_competitors.set_index('MeetID')
powerlifting_combined = meets.join(competitors)
# Check your answer
q4.check()
Correct
powerlifting_combined.columns
Index(['MeetPath', 'Federation', 'Date', 'MeetCountry', 'MeetState', 'MeetTown', 'MeetName', 'Name', 'Sex', 'Equipment', 'Age', 'Division', 'BodyweightKg', 'WeightClassKg', 'Squat4Kg', 'BestSquatKg', 'Bench4Kg', 'BestBenchKg', 'Deadlift4Kg', 'BestDeadliftKg', 'TotalKg', 'Place', 'Wilks'], dtype='object')
#q4.hint()
q4.solution()
Solution:
powerlifting_combined = powerlifting_meets.set_index("MeetID").join(powerlifting_competitors.set_index("MeetID"))
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.
If you'd like to apply your new skills to examining geospatial data, you're encouraged to check out our Geospatial Analysis micro-course.
You can also take advantage of your Pandas skills by entering a Kaggle Competition or by answering a question you find interesting using Kaggle Datasets.
Have questions or comments? Visit the Learn Discussion forum to chat with other Learners.