Skip to content
0

Everyone Can Learn Python Scholarship

SOLUTIONS - Which cars are cleaner? Exploring Canadian vehicle CO₂ emissions

In this analysis, I use seven years of Canadian vehicle data to answer:

  • Which vehicles and fuel types tend to emit less CO₂?
  • How engine size and fuel consumption relate to emissions.
  • Practical recommendations for policy and consumers.
import pandas as pd
import numpy as np

# Load the data
cars = pd.read_csv('data/co2_emissions_canada.csv')

# Preview the dataframe
cars.head()
cars.info()
cars.describe()
cars.isna().sum()

The dataset contains 9 rows of vehicles, and the key numeric variables (engine size, fuel consumption, CO₂ emissions) have no missing values. This allows us to calculate averages and correlations reliably.

Question 1 – Median engine size

median_engine_size = cars['Engine Size(L)'].median()
median_engine_size

**Median engine size

The median engine size in the dataset is 3.4 liters.
This means that half of the vehicles have engines of 3.4 L or smaller, and half have engines larger than that. This gives a sense of what a “typical” engine size looks like in Canada over these years.**

Question 2 – Average fuel consumption by fuel type

We want the average combined fuel consumption for fuel types:

Regular gasoline (X)

Premium gasoline (Z)

Ethanol (E)

Diesel (D)

fuel_consumption_by_type = (
    cars
    .groupby('Fuel Type')['Fuel Consumption Comb (L/100 km)']
    .mean()
    .round(2)
)

fuel_consumption_by_type
 #or printing just the four types of fuel consumption
fuel_types_of_interest = ['X', 'Z', 'E', 'D', 'N']
fuel_consumption_by_type.loc[fuel_types_of_interest]

Fuel consumption by fuel type

Average combined fuel consumption (L/100 km):

  • Regular gasoline (X): 10.08 L/100 km
  • Premium gasoline (Z): 11.42 L/100 km
  • Ethanol (E): 16.86 L/100 km
  • Diesel (D): 8.84 L/100 km

Diesel typically shows lower fuel consumption per 100 km compared to gasoline, which often translates into lower CO₂ emissions per km, although diesel fuel itself can have other environmental trade-offs.

fuel_consumption_by_type.loc[fuel_types_of_interest].plot(kind='bar')

Question 3 – Correlation between fuel consumption and CO₂ emissions

We want the correlation coefficient between:

Fuel Consumption Comb (L/100 km)

CO2 Emissions(g/km)