## Everyone Can Learn Python Scholarship

### 📖 Background

The first "Everyone Can Learn Python" Scholarship from DataCamp is now open for entries.

The challenges below test the Python and SQL skills you gained from Introduction to Python and Introduction to SQL and pair them with your existing problem-solving and creative thinking.

The scholarship is open to people who have completed or are completing their secondary education and are preparing to pursue a degree in computer science or data science. Students preparing for graduate-level computer science or data science degrees are also welcome to apply.

### 💡 Learn more

The following DataCamp courses can help review the skills needed for this challenge:

### ℹ️ Introduction to Data Science Notebooks

You can skip this section if you are already familiar with data science notebooks.

#### Data science notebooks

A *data science notebook* is a document containing text cells (what you're reading now) and code cells. What is unique with a notebook is that it's **interactive**: You can change or add code cells and then **run** a cell by selecting it and then clicking the **Run** button to the right ( **▶**, or Run All on top) or hitting `control + enter`

.

The result will be displayed directly in the notebook.

Try running the Python cell below:

```
# Run this cell to see the result (click on Run on the right, or control+enter)
100 * 1.75 * 20
```

Modify any of the numbers and rerun the cell.

You can add a Markdown, Python, or SQL cell by clicking on the **Add Markdown**, **Add Code**, and **Add SQL** buttons that appear as you move the mouse pointer near the bottom of any cell.

Here at DataCamp, we call our interactive notebook **Workspace**. You can find out more about Workspace here.

### 1️⃣ Python 🐍 - CO2 Emissions

Now let's now move on to the competition and challenge.

### 📖 Background

You volunteer for a public policy advocacy organization in Canada, and your colleague asked you to help her draft recommendations for guidelines on CO2 emissions rules.

After researching emissions data for a wide range of Canadian vehicles, she would like you to investigate which vehicles produce lower emissions.

### 💾 The data I

#### You have access to seven years of CO2 emissions data for Canadian vehicles (source):

- "Make" - The company that manufactures the vehicle.
- "Model" - The vehicle's model.
- "Vehicle Class" - Vehicle class by utility, capacity, and weight.
- "Engine Size(L)" - The engine's displacement in liters.
- "Cylinders" - The number of cylinders.
- "Transmission" - The transmission type: A = Automatic, AM = Automatic Manual, AS = Automatic with select shift, AV = Continuously variable, M = Manual, 3 - 10 = the number of gears.
- "Fuel Type" - The fuel type: X = Regular gasoline, Z = Premium gasoline, D = Diesel, E = Ethanol (E85), N = natural gas.
- "Fuel Consumption Comb (L/100 km)" - Combined city/highway (55%/45%) fuel consumption in liters per 100 km (L/100 km).
- "CO2 Emissions(g/km)" - The tailpipe carbon dioxide emissions in grams per kilometer for combined city and highway driving.

The data comes from the Government of Canada's open data website.

```
# Import the pandas and numpy packages
import pandas as pd
import numpy as np
# Load the data
cars = pd.read_csv('data/co2_emissions_canada.csv')
# create numpy arrays
cars_makes = cars['Make'].to_numpy()
cars_models = cars['Model'].to_numpy()
cars_classes = cars['Vehicle Class'].to_numpy()
cars_engine_sizes = cars['Engine Size(L)'].to_numpy()
cars_cylinders = cars['Cylinders'].to_numpy()
cars_transmissions = cars['Transmission'].to_numpy()
cars_fuel_types = cars['Fuel Type'].to_numpy()
cars_fuel_consumption = cars['Fuel Consumption Comb (L/100 km)'].to_numpy()
cars_co2_emissions = cars['CO2 Emissions(g/km)'].to_numpy()
# 1st taks is finding the median engine size
# we are using for that reason the method "median"
median_engine_sizes = np.median(cars_engine_sizes)
print("1. Median engine size in liters " + str(median_engine_sizes) + "L \n")
# 2nd task is to find average fuel consumption of different fuel types
# first we are filtering the list of "cars" to the different fuel types
z_fuel_type = cars_fuel_consumption[cars_fuel_types == 'Z']
x_fuel_type = cars_fuel_consumption[cars_fuel_types == 'X']
d_fuel_type = cars_fuel_consumption[cars_fuel_types == 'D']
e_fuel_type = cars_fuel_consumption[cars_fuel_types == 'E']
# than using the method "mean()" to find the average fuel consumption
average_z_fuel_size = str(np.mean(z_fuel_type))
average_x_fuel_size = str(np.mean(x_fuel_type))
average_d_fuel_size = str(np.mean(d_fuel_type))
average_e_fuel_size = str(np.mean(e_fuel_type))
print("\n2. Average fuel consumption for regular gasoline: " + average_x_fuel_size,"\n Average fuel consumption for premium gasoline: " + average_z_fuel_size,"\n Average fuel consumption for ethanol: " + average_e_fuel_size,"\n Average fuel consumption for diesel: " + average_d_fuel_size,)
# 3rd task is: What is the correlation between fuel consumption and CO2 emissions?
# checking the correlation between fuel consumption and CO2 emmisions by using the method "corrcoef()"
correlation = np.corrcoef(cars_fuel_consumption,cars_co2_emissions)
print("\n3. The correlation coeficient between fuel consumption and CO2 emissions is: " + str(correlation) + "\n Showing how close to 1(0.918) is the coefficient means that is strong positive the correlation")
# 4th task is: Which vehicle class has lower average CO2 emissions, 'SUV - SMALL' or 'MID-SIZE'?
# we gonna filter the list of emission and then save separately the average CO2 emissions of 'SUV - SMALL' and 'MID-SIZE'
co2_emissions_suv_small = cars_co2_emissions[cars_classes == 'SUV - SMALL']
co2_emissions_mid_size = cars_co2_emissions[cars_classes == 'MID-SIZE']
avg_suv_small_emissions = np.mean(co2_emissions_suv_small)
avg_mid_size_emissions = np.mean(co2_emissions_mid_size)
# then we compare both cars' emissions who has lower average
if avg_suv_small_emissions > avg_mid_size_emissions:
print("MID-Size cars has lower average emissions")
elif avg_suv_small_emissions < avg_mid_size_emissions
print("")
print(avg_suv_small_emissions)
# Preview the dataframe
cars
```

### 💪 Challenge I

Help your colleague gain insights on the type of vehicles that have lower CO2 emissions. Include:

- What is the median engine size in liters?
- What is the average fuel consumption for regular gasoline (Fuel Type = X), premium gasoline (Z), ethanol (E), and diesel (D)?
- What is the correlation between fuel consumption and CO2 emissions?
- Which vehicle class has lower average CO2 emissions, 'SUV - SMALL' or 'MID-SIZE'?
- What are the average CO2 emissions for all vehicles? For vehicles with an engine size of 2.0 liters or smaller?
- Any other insights you found during your analysis?

### 2️⃣ SQL - Understanding the bicycle market

### 📖 Background

You work for a chain of bicycle stores. Your new team leader comes from a different industry and wants your help learning about the bicycle market. Specifically, they need to understand better the brands and categories for sale at your stores.

### 💾 The data II

#### You have access to the following tables:

##### products

- "product_id" - Product identifier.
- "product_name" - The name of the bicycle.
- "brand_id" - You can look up the brand's name in the "brands" table.
- "category_id" - You can look up the category's name in the "categories" table.
- "model_year" - The model year of the bicycle.
- "list_price" - The price of the bicycle.

##### brands

- "brand_id" - Matches the identifier in the "products" table.
- "brand_name" - One of the nine brands the store sells.

##### categories

- "category_id" - Matches the identifier in the "products" table.
- "category_name" - One of the seven product categories in the store.

### A note on SQL

You can click the "Browse tables" button in the upper right-hand corner of the SQL cell below to view the available tables. They will show on the left of the notebook.

It is also important to note that the database used in this challenge is a slightly different version (SQL Server) from the one used in the Introduction to SQL course (PostgreSQL). You might notice that the keyword **LIMIT** does not exist in SQL Server.

```
SELECT *
FROM products;
```

`SELECT * FROM brands;`