Question: For a collection of things in the world, an array is useful for describing a single attribute of each thing. For example, among the collection
For a collection of things in the world, an array is useful for describing a single attribute of each thing. For example, among the collection of US States, an array could describe the land area of each. Tables extend this idea by describing multiple attributes for each element of a collection.
In most data science applications, we have data about many entities, but we also have several kinds of data about each entity.
For example, in the cell below we have two arrays. The first one contains the world population in each year estimated by the US Census Bureau and the second contains the years themselves. These elements are in order, so the year and the world population for that year have the same index in their corresponding arrays.
populationamounts Table.readtableworldpopulation.csvcolumnPopulation
years nparange
printPopulation column:", populationamounts
printYears column:", years
Population column:
Years column:
Suppose we want to answer this question:
When did world population cross billion?
You could technically answer this question just from staring at the arrays, but it's a bit convoluted, since you would have to count the position where the population first crossed billion, then find the corresponding element in the years array. In cases like these, it might be easier to put the data into a Table, a twodimensional type of dataset.
The expression below:
creates an empty table using the expression Table
adds two columns to the table by calling withcolumns with four arguments column and data for each
assigns the result to the name population, and finally
evaluates population so that we can see the table.
The strings "Year" and "Population" are column labels that we have chosen. Ther names populationamounts and years were assigned above to two arrays of the same length. The function withcolumns you can find the documentation here takes in alternating strings to represent column labels and arrays representing the data in those columns which are all separated by commas. Tip: Both populationamounts and years need the same number of data points or an error will be returned on attempting to construct the table.
population Tablewithcolumns
"Population", populationamounts,
"Year", years
population
Population Year
rows omitted
Now the data are all together in a single table! It's much easier to parse this dataif you need to know what the population was in for example, you can tell from a single glance. We'll revisit this table later.
Question
From the example in the cell above, identify the variables or data types for each of the following: which variable contains the table? which variable contains an array? On the right of the equals sign provide the correct variable name. Note that in the cell above we defined one table, which contains two arrays, so you can pick either array variable for your answer.
tablevar
arrayvar
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
