Instructions: Work with a neighbor to answer the following questions. To get started, download the class activity template file.
In this activity, we will revisit the Gapminder data that we have worked with previously. To load the Gapminder data into Python, run the following code in R:
Then run the following code in Python:
Use Python and pandas to complete the following questions.
Choose only the rows in the gapminder data for countries in Asia in 2002.
Count the number of countries in each continent for the data in 2002. (hint: use the 'count'
function in agg
)
Use the assign
function to create a new column which contains the natural log of GDP per capita. (You may need to look up pandas documentation for the assign
function).
Create the following table:
## num_countries mean_log_gdp
## continent
## Africa 52 7.367332
## Americas 25 8.847365
## Asia 33 8.542181
## Europe 30 9.808402
## Oceania 2 10.191543