This chapter used external data sources as input into Python programs. Some of these data sources, called text files, can reside on a local machine or may be available via the Internet. We showed how to create formatted output by using format strings, which allows for structured output as well as formatted numeric values, columns of data, and justification. We used list comprehension to filter the external data. We also accessed real earthquake data on the Internet in both CSV and JSON formats and used statistical functions to analyze the data. Finally, we developed another statistical function called correlation.
5.1 Write a program to correlate gross domestic product (GDP) and personal income—specifically, wages and salaries. GDP is the value of all goods and services in the U.S. economy. The Bureau of Economic Analysis makes this data available in the public domain.
To work with the latest data, go to the website of the Bureau of Economic Analysis and find the page for “Interactive Data Application” (https://apps.bea.gov/itable/). Click on “GDP and Personal Income” under National Data; then click “Begin using this data.” In Section 1, choose the table for “Gross Domestic Product.” Download this table in CSV format. In Section 2, select the table for “Personal Income and its disposition.” Download this table in CSV format. Write functions to extract the GDP and Wages and Salaries data into two lists. Then run the chapter’s correlation
function to see whether GDP and Wages and Salaries are related.
Design Credits: Calculator Icon made by Smashicons from www.flaticon.com
3.142.156.255