Exercise 5
Create Table for Aggregate Country Temperatures
The objective of this exercise is to aggregate temperature measurements per country on an annual basis using the data from the stg_temperatures_by_country
source. Additionally, you will need to clean up the "Country" column by removing leading/trailing spaces and converting the country names to the proper format.
To create a table called aggregate_country_temperatures
with the desired columns in the global_temperatures
schema:
- Open your dbt project and navigate to the appropriate schema directory (e.g.,
models/global_temperatures
). - Create a new file named
aggregate_country_temperatures.sql
(or any desired name) in the schema directory. - In the
aggregate_country_temperatures.sql
file, write the dbt model definition for the table. - Define the
aggregate_country_temperatures
model using thetable
materialization type. - Investigate the data in the
stg_temperatures_by_country
source for any data quality issues and address them as necessary. - Clean up the "Country" column by removing leading/trailing spaces and converting the country names to the proper format. You can use the
initcap
function for this purpose. - Remove any occurrences of the Lenny face '( ͡° ͜ʖ ͡°)' from the
AverageTemperature
column. - Aggregate the temperature measurements per country on an annual basis.
- Ignore any 'Uncertainty' columns for this project.
- Select the following columns for the output table:
Year
: IntegerCountry
: StringAverageTemperature
: Float
By following these instructions and executing the appropriate dbt commands, you will create a table called aggregate_country_temperatures
in the global_temperatures
schema. The table will contain the aggregated temperature measurements per country on an annual basis, with the specified columns as outlined above.