2 Data frames

 

Since long before the invention of computers, people have used tables to present data. That’s because tables make it easy to enter, display, understand, and analyze data. Each row in a table represents a single record or data point, and every column describes an attribute associated with each point. For example, consider table 2.1 of country names, sizes (in square kilometers), and populations, with data taken from Wikipedia toward the end of 2022.

Table 2.1 Country data (view table figure)

Country

Area (sq km)

Population

United States

9,833,520

331,893,745

United Kingdom

93,628

67,326,569

Canada

9,984,670

38,654,738

France

248,573

67,897,000

Germany

357,022

84,079,811

If it seems obvious to arrange data this way, that’s because we’ve seen it for so long and in so many contexts. Indeed, here are some examples of tables I’ve seen in just the last few days:

  • Stock-market updates—The rows are stocks and popular indexes, and the columns are the current value, the absolute change since yesterday, and the percentage change since yesterday.
  • Luggage allowances on international flights—The rows describe different types of tickets, and the columns indicate how large or heavy our carry-on and checked bags can be.
  • Nutrition information on packaged food—The rows are different items we want to know about (for example, calories, fat, and sugar), and the columns describe the quantity per 100 grams or for an entire package.

Exercise 8 Net revenue

Working it out

Solution

Beyond the exercise

Exercise 9 Tax planning

Working it out