✅ Week 04 Lab - Solutions

Author

Click on the button below to download the solution to the Week 04 lab.

Solutions v1 - python loops + step-by-step debugging

Here I offer you a guide on how to reason about the problems. Writing code is an iterative process. You will write code, test it, debug it, and repeat. The more you practice, the better you will get at it.

This version of the solutions uses pure python lists and for loops, closer to what you might have learned in your python courses prior to DS105. We only uses pandas at the very end, when creating the data frame. If you are new to Python, this should be easier to follow.

Solution v2 - with list indexing + pandas.apply() + custom functions + pagination

If you are already familiar with pandas apply() and anonymous functions in Python, the alternative solution contained in the notebook below might be for you.

You will see a different way to get ‘every other element of a list’ , and examples of how to manipulate an existing pandas DataFrame. You will also encounter samples of custom functions and how to ‘move’ to different pages (pagination).