ECS 10 Announcements Makeup Assignment Macroeconmics Data ...

4 downloads 34 Views 346KB Size Report
Macroeconmics. □ Economics at the world scale. □ Current Account Balance is like income – balance of trade, foreign aid, interest and dividends on foreign.
Announcements !  ! 

No lecture Wds, also no section. I will be in Lab hours Wds, and we will do some work on dictionaries and file writing.

ECS 10 11/19

Makeup Assignment ! 

Files, dictionaries, file writing, sorting.

Macroeconmics Economics at the world scale. Current Account Balance is like income – balance of trade, foreign aid, interest and dividends on foreign investment. !  Does not include domestic production or consumption; just income with respect to the rest of the world. !  US’s CAB a big negative number, China’s CAB a big positive number. !  ! 

! 

Current Account Balance

Data source

Data source

Maybe we should not freak out. USA is a big economy; the fact that it has the biggest anything in the world might not be a disaster. !  We buy a lot of stuff; mostly stuff from China and oil. !  if we weren’t going into debt, it would not be a problem at all. !  Are we buying more stuff at a higher rate than other countries? !  Compare CAB and GDP (size of economy). ! 

Combine two data files Get CAB and GDP lists from CIA. Combine by country. !  Use a dictionary where country is the key. !  Read one file, say GDP, build dictionary. !  Read CAB file, look up country, get GDP, and compute R. !  Save [R, country name] in a list of lists. !  Very common data wrangling task.

Goal Compute R = CAB/GDP for each country Produce a list of countries, sorted by R !  Write out file readable in Excel, ManyEyes… !  Where does USA show up in this list? China? !  ! 

Skills: combining data !  Sorting !  3 loops ! 

Sorting

! 

Sorting is putting a list into order – A,B,C… or 1,2,3… !  Python has a sort method for lists.

Sorting list of lists?

Data file formats

! 

!  ! 

Sorts by FIRST ITEM in each list. So if we want to sort by R, R better be the first item in each list.

! 

Excel, ManyEyes, other programs read text files containing data. !  Issues with multi-part names, etc, make it hard to use plain text files. !  .csv – commas separate data items !  .tsv – tabs separate data items !  This CIA data is tab-separated !  We’d like to produce tab-separated output file ! 

Let’s sort something real… !  ! 

State population file, but tab-separated Sort by population

Output file

Make list of lists