LESSON 7: Creating a new column and retrieving a data column from tables

To create a new column in a given table we must open all the files that will be used to retrieve data from. Click on the Input/Output tab from the library window and grab three “Load Lookup Table” Functors and one “Load Table” placing them on the sketch. Open the Load Lookup Table functors and load the files Tables\1999_production_value.csv, Tables\1999_harvested_area.csv and Tables\1999_production.csv. Next, open the Load Table functor and load the file IBGE_crop_information_uptated.csv.
Now we can create a new column merge with 1999_harvested_area.csv and 1999_production.csv files. Click on the Input/Output tab from the library window, grab an Add Table Column and place it on the sketch. Connect the Load Lookup Table which contains the file 1999_harvested_area.csv to Add Table Column. On the Functor Editor window, write a name for the created column (e.g. “production_value”).

The position where the new column is inserted determines whether the new column is a key or data column.

Connect the Load Lookup Table which contains the file 1999_production.csv to Add Table Column. Finally, connect the Load Lookup Table which contains the file IBGE_crop_information_uptated.csv to Set Table by Key. To save the result to a file, open Save Map functor and browse to Dinamica EGO\Guidebook Dinamica_4\Models\Set_2\basics\ to determine where the file will be saved and write the name file (e.g. IBGE_crop_information_complete.csv).
Mark the eye button at the top of Save Table to view the result.
Click on the layout tool Execute Layout. Your final model should be similar to the one below:
Save and run the model. Click on eye button of “Save Table” to see the result. This functor output is table that looks like this:
Now, using the table generated previously, we would like to demonstrate how to retrieve a data column from it.
First, grab a Load Table, placing it on the sketch. Double click the Load Table Functor and open the IBGE_crop_information_complete.csv file.
To retrieve a data column table corresponding to harvested area, we will use a Get Table Column functor. Connect the Load Table to Get Table Column. In the tab Column Index or Name, insert the index of the column to be retrieved (“3” or “harvested area”).
Now, we can retrieve the harvested area per crop corresponding to the year of 2004. For this, grab a “Get Table from key” and place it on the sketch. Connect the Get Table Column to Get Table from Key. In the tab “Keys”, insert the year you want to retrieve the harvested area per crop (In this example, “2004”).
Grab a “Save Table” and place it on the sketch. Connect the functor Get Table from Key and Save Table. The final model should have the following structure:
To save the result to a file, open Save Map, browse to Documents\GuideBook Dinamica\Guidebook Dinamica_4\Models\Set_2\basics\ Get_Table_from_Key and write the file name (e.g. IBGE_crop_information_update).
Click on the eye icon at the top of “Save Table” to mark the results for inspection. Save and run the model. To see the resulting table, click on eye button of “Save Table”. This functor output is a table that looks like this:
Congratulations, you have successfully completed this lesson!
☞ Next Lesson
☞ Back to Guidebook Start