5.5 Summary

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.

Key Terms

  • comma-separated values (CSV)

  • formatted string

  • filtering

  • infinite loop

  • iterator

  • JSON

  • list comprehension

  • metadata

  • Pearson correlation coefficient

  • text file

  • Uniform Resource Locator (URL)

Python Keywords and Functions

  • as

  • close

  • format

  • loads

  • open

  • read

  • readline

  • readlines

  • urllib.request

  • urlopen

  • while

  • with

  • write

Programming Exercise

  1. 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

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.142.156.255