Path: blob/master/03_Grouping/Alcohol_Consumption/Exercise_with_solutions.ipynb
819 views
Kernel: Python 3 (ipykernel)
Ex - GroupBy
Check out Alcohol Consumption Exercises Video Tutorial to watch a data scientist go through the exercises
Introduction:
GroupBy can be summarized as Split-Apply-Combine.
Special thanks to: https://github.com/justmarkham for sharing the dataset and materials.
Check out this Diagram
Step 1. Import the necessary libraries
In [2]:
Step 2. Import the dataset from this address.
Step 3. Assign it to a variable called drinks.(Watch the values of Column continent NA (North America), and how Pandas interprets it!
In [4]:
Out[4]:
Step 4. Which continent drinks more beer on average?
In [5]:
Out[5]:
continent
AF 61.471698
AS 37.045455
EU 193.777778
NA 145.434783
OC 89.687500
SA 175.083333
Name: beer_servings, dtype: float64
Step 5. For each continent print the statistics for wine consumption.
In [6]:
Out[6]:
Step 6. Print the mean alcohol consumption per continent for every column
In [7]:
Out[7]:
Step 7. Print the median alcohol consumption per continent for every column
In [8]:
Out[8]:
Step 8. Print the mean, min and max values for spirit consumption for each Continent.
This time output a DataFrame
In [9]:
Out[9]:
In [ ]: