<jupyter_start><jupyter_text>Ex - GroupBy  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](http://i.imgur.com/yjNkiwL.png)   Step 1. Import the necessary libraries<jupyter_code>import pandas as pd<jupyter_output><empty_output><jupyter_text>Step 2. Import the dataset from this [address](https://raw.githubusercontent.com/justmarkham/DAT8/master/data/drinks.csv).   Step 3. Assign it to a variable called drinks.<jupyter_code>drinks = pd.read_csv('https://raw.githubusercontent.com/justmarkham/DAT8/master/data/drinks.csv',
            sep=',')
drinks<jupyter_output><empty_output><jupyter_text>Step 4. Which continent drinks more beer on average?<jupyter_code>drinks.dtypes
# strinks = drinks.continent.convert_dtypes(infer_objects=False, convert_string=True)


as_drinks = drinks[drinks.continent == 'AS']
AS_litres = as_drinks.total_litres_of_pure_alcohol.sum()

na_drinks = drinks[drinks.continent == 'NA']
NA_litres = na_drinks.total_litres_of_pure_alcohol.sum()

eu_drinks = drinks[drinks.continent == 'EU']
EU_litres = eu_drinks.total_litres_of_pure_alcohol.sum()

sa_drinks = drinks[drinks.continent == 'SA']
SA_litres = sa_drinks.total_litres_of_pure_alcohol.sum()

af_drinks = drinks[drinks.continent == 'AF']
AF_litres = af_drinks.total_litres_of_pure_alcohol.sum()

au_drinks = drinks[drinks.continent == 'AU']
AU_litres = au_drinks.total_litres_of_pure_alcohol.sum()

continent_litres = [AS_litres, NA_litres, EU_litres, SA_litres, AF_litres, AU_litres]
continent_litres

# I was able to come to the conclusion that Europe is the winner here,
# but again, I"m going about this in a hugely round about way.
# all it takes to get an answer is 1 line of code...
# I'll need to learn more or try again when my brain isn't tired.

# here is the better way to do this:

drinks.groupby('continent').beer_servings.mean()<jupyter_output><empty_output><jupyter_text>Step 5. For each continent print the statistics for wine consumption.<jupyter_code>drinks.groupby('continent').wine_servings.describe()<jupyter_output><empty_output><jupyter_text>Step 6. Print the mean alcohol consumption per continent for every column<jupyter_code>drinks.groupby('continent').mean()<jupyter_output><empty_output><jupyter_text>Step 7. Print the median alcohol consumption per continent for every column<jupyter_code>drinks.groupby('continent').median()<jupyter_output><empty_output><jupyter_text>Step 8. Print the mean, min and max values for spirit consumption. This time output a DataFrame<jupyter_code>drinks.groupby('continent').mean().min().max()
drinks.groupby('continent').spirit_servings.agg(['mean', 'min', 'max'])
# ...maybe data science isn't for me, or maybe my mind is just soup today and
# none of this makes any sense...<jupyter_output><empty_output>
StarcoderdataJupyterStructuredCleanDedup