Skip to content
0
  1. What is the median engine size in liters?

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? (Done) 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?

Challenge II: Help your team leader understand your company's products. Include:

What is the most expensive item your company sells? The least expensive? How many different products of each category does your company sell? What are the top three brands with the highest average list price? The top three categories? Any other insights you found during your analysis?
#1. What is the median engine size in liters?
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
#Index(['Make', 'Model', 'Vehicle Class', 'Engine Size(L)', 'Cylinders',
       #'Transmission', 'Fuel Type', 'Fuel Consumption Comb (L/100 km)',
       #'CO2 Emissions(g/km)'],

dbase = pd.read_csv("data/co2_emissions_canada.csv")

mes_in_liters = dbase["Engine Size(L)"].agg(np.median)

sns.catplot(y="Engine Size(L)", data=dbase, kind="box")

plt.title("Box plot of Engine Size distribution", c="r")

print("Like we can see in the next plot, the median engine size in liters is " + str(mes_in_liters))

What is the average fuel consumption for regular gasoline (Fuel Type = X), premium gasoline (Z), ethanol (E), and diesel (D)?

mfuels = dbase[['Fuel Type','Fuel Consumption Comb (L/100 km)']]
#sol = mfuels[mfuels["Fuel Type"] == "Z"]["Fuel Consumption Comb (L/100 km)"].mean()
def sol(fuel):
    val = mfuels[mfuels["Fuel Type"] == fuel]["Fuel Consumption Comb (L/100 km)"].mean()
    result = print("The consumption of " + fuel + " is " + str(val))
    return result



sol("X")
sol("Z")
sol("E")
sol("D")


#["Fuel Consumption Comb (L/100km)"]

#favstat = ["X", "Z", "E", "D"]

#for comb in favstat:
 #   phil = mfuels[]
    

sns.catplot(x="Fuel Type", y="Fuel Consumption Comb (L/100 km)", data=dbase, kind="box")
plt.show()



#Index(['Make', 'Model', 'Vehicle Class', 'Engine Size(L)', 'Cylinders',
       #'Transmission', 'Fuel Type', 'Fuel Consumption Comb (L/100 km)',
       #'CO2 Emissions(g/km)'],