Before you keep reading...
Runestone Academy can only continue if we get support from individuals like you. As a student you are well aware of the high cost of textbooks. Our mission is to provide great books to you for free, but we ask that you consider a $10 donation, more if you can or less if $10 is a burden.
Before you keep reading...
Making great stuff takes time and $$. If you appreciate the book you are reading now and want to keep quality materials free for other students please consider a donation to Runestone Academy. We ask that you consider a $10 donation, but if you can give more thats great, if $10 is too much for your budget we would be happy with whatever you can afford as a show of support.
6.9. Case Study 2: Comparing CIA Government Forms¶
The goal of this section is to be able to summarize, sort, and organize data using pivot tables. In the previous case study project, you retrieved the government types from the “list of countries by system of government” website. However, in this case study, you will work with the data that you scraped from the CIA World Factbook website. You will compare different forms of government and how the form of government might impact the countries’ economic success. For this example, measure financial stability based on GDP. You can do this by building a pivot table in Pandas.
If you haven’t already, you should review the example of ref:screenscrape_Bus. This will show you the basics of reading and grabbing information out of a page.
1. If you scraped the whole data from CIA World Factbook 2017 in the previous exercise, you should be able to use the government type field from the CSV file you saved. If not, try and scrape the government type fields.
2. For this exercise, you should have a row for every region, a column for government forms; then, in each cell, we would like to summarize the fraction of the economy that comes from GDP.
3. Remember, if the information you choose is numeric, you can change it to nominal using the
a lambda function, and a dictionary that maps from that specific column number to a label.
4. Now, let’s pivot the table. Remember, the pivot table method takes three parameters:
If you recall from the previous case study, the
pivot function works like the
pivot_table function but does not do
any aggregation. Therefore, it will throw an error if you have duplicate index
Try changing the values parameter to be a list of columns may be agriculture, inflation rate and, industry. How does that change your table?
During this lesson I was primarily in my...
- 1. Comfort Zone
- 2. Learning Zone
- 3. Panic Zone
Completing this lesson took...
- 1. Very little time
- 2. A reasonable amount of time
- 3. More time than is reasonable
Based on my own interests and needs, the things taught in this lesson...
- 1. Don't seem worth learning
- 2. May be worth learning
- 3. Are definitely worth learning
For me to master the things taught in this lesson feels...
- 1. Definitely within reach
- 2. Within reach if I try my hardest
- 3. Out of reach no matter how hard I try