Python pandas—Grouping Exercise—Alcohol Consumption




[ad_1]

Sometimes we learn best by doing. Unlike my other videos, I’ll be going through these exercises cold. Sometimes we’ll encounter ambiguous questions, and sometimes I’ll be wrong. Learning from our mistakes can be a powerful teacher. So, it’s OK to be wrong now, because we’ll know how to avoid it next time when it counts. My hope is that you will learn by doing. Why don’t you proceed through the linked exercises before we walk through them together? This series can be viewed in tandem with my “An Opinionated Guide to pandas“ video series (links below), but it’s not required. This series is beginner-friendly but aimed most directly at intermediate users.

This Learning by Doing is part of the pandas indexing and selecting:
https://youtu.be/Pau9An-fQZk

https://github.com/knathanieltucker/pandas-tutorial/blob/master/notebooks/Indexing%20and%20Selecting.ipynb

Here’s a link to the Grouping — Alcohol Consumption: https://github.com/guipsamora/pandas_exercises/tree/master/04_Apply/Students_Alcohol_Consumption

Source


[ad_2]

Comment List

  • Data Talks
    December 3, 2020

    In case people wonder why there is North America, that's because its continent code is 'NA' and that was regarded as null by pd.read_csv. A good example to be careful with parsing your data!

    To prevent this, we can pass keep_default_na=False to pd.read_csv

  • Data Talks
    December 3, 2020

    Took 30mins to get it all done!
    Functions I learned from this lecture:
    df.groupby('a')['b'].mean()
    df.groupby('a')['b'].describe()
    df.groupby('a')['b'].median()
    df.groupby('a')['b'].agg(['min','max','mean'])

  • Data Talks
    December 3, 2020

    Thanks for all the lovely exercises videos. kind of gem here !
    Concerning question 8, it can be ;
    drinks.groupby("continent").spirit_servings.describe()[["mean","max","min"]]

  • Data Talks
    December 3, 2020

    Step 4 Which continent drinks more beer on average? doesn't this mean that we need to find average beer consumption continent wise and then compare with each continent consumption to find out which one consumes more than the average. Please correct me if I am wrong.

  • Data Talks
    December 3, 2020

    Thanks for that, I had never used or seen anyone else use the 'agg' method before. I prefer returning a df

Write a comment