Chapter 5 questions

Try to use pandas method to handle it, I recommend using groupby()