4. Day 2 Homework#

Here is a csv file that contains all of the countires that medalled in the 2018 Winter Olympic games, their latitudes and longitudes, medals won, GDP (2018), and population (2018). This time, we are going to plot the countries that medalled and add more information

4.1. Initial Instructions:#

  1. Download the csv file from the link above.

  2. Open a new Google Colab notebook and click on “New Notebook” in the corner.

  3. Click the file icon on the left toolbar, then click on the upload icon (the button on the left).

  4. Choose the new .csv file to upload in order to import the data.

  5. Here’s the actual homework!

4.2. Assignment#

  • Open the csv file and examine what’s in it. What variable types are in here? Strings, floats, or integers?

  • In your Colab notebook, write a script that imports the data from the file to make a scatter plot.

  • As you parse the data, for each country you’ll need to tally up the total medals. You will also need to calculate GDP per 5000 capita (GPD per 5000 people).

    • What techniques that we have reviewed can we use to accomplish these?

  • This time when you plot the data, color the countries according to number of medals won, and change the size of each point based on GPD per capita.

  • Add the equator to the plot as well.

  • Congrats! You are all done.

  • The plot will have fewer points this time without the countires that did not medal, but contain more information about those countries. If you want a challenge, the advanced homework will add more complexity and the other countries!

  • In Day 3 we will delve into using more libraries and do more data analysis.

4.3. Bonus Homework#

4.4. Assignment: Approximate pi with random numbers#

π is among the most famous of irrational numbers, written approximately as 3.14159. An enormous amount of resources, both human and machine, have exhausted countless hours analyzing π’s decimal contributions, and roughly 100 trillion digits of π are known today. [http://www.numberworld.org/y-cruncher/]

A far less ambitious approximation can be achieved with simple Monte Carlo methods, utilizing random numbers and statistics to converge an estimate for π. Imagine a circle of diameter D inscribed within a square of edge length D. Place the origin of a 2D graph at the circle’s center. The key to approximating π is generating coordinate pairs of random numbers, which correspond to (x,y) positions inside of the square, and counting how many land inside the circle. With a statistically large random sample of coordinate pairs, the ratio of points landing inside the circle to total number of points approximates the ratio of the circle’s area to the square’s area. This is known as the stone throwing problem and is mathmatically formulated as:
AcircleAsquare=NcircleNsquare
where A represents the shape area and N represents the number of points to land inside of each shape. Note that all generated points should land within the square, such that Ntotal=Nsquare. Using a little geometry, Acircle=π(D2)2 and Asquare=D2, the final relation for π is given as:
π4NcircleNsquare

4.5. Instructions#

  1. Generate a set of N random x,y pairs within a square (2*N random numbers makes N pairs of random numbers)

  2. Count the x,y pairs lying inside of an inscribed circle (is x2+y2<(D2)2 ?)

  3. Compute an approximation of π

4.6. Answer#

.ipynb file

plot image

4.7. Bonus Homework Answer#

.ipynb file