diff --git a/src/visualization/dash-app-vis.ipynb b/src/visualization/dash-app-vis.ipynb index 4034baf..6ac47cb 100644 --- a/src/visualization/dash-app-vis.ipynb +++ b/src/visualization/dash-app-vis.ipynb @@ -394,7 +394,7 @@ }, { "cell_type": "code", - "execution_count": 77, + "execution_count": 108, "metadata": {}, "outputs": [ { @@ -417,859 +417,3930 @@ "\n", " \n", " \n", - " \n", + " \n", + " \n", + " \n", " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", " \n", " \n", " \n", + " \n", + " \n", " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", - " \n", " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", " \n", - " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", - " \n", " \n", - " \n", - " \n", - " \n", - " \n", " \n", - " \n", " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", " \n", - " \n", " \n", + " \n", + " \n", + " \n", " \n", " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", - " \n", " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", " \n", - " \n", " \n", - " \n", - " \n", - " \n", - " \n", " \n", - " \n", " \n", + " \n", + " \n", + " \n", " \n", " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", - " \n", - " \n", - " \n", - " \n", " \n", - " \n", " \n", - " \n", - " \n", - " \n", - " \n", " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", " \n", - " \n", " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", " \n", + " \n", + " \n", + " \n", " \n", " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", " \n", " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", " \n", - " \n", " \n", - " \n", - " \n", - " \n", - " \n", " \n", - " \n", " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", " \n", " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", - " \n", " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", " \n", - " \n", " \n", - " \n", - " \n", - " \n", - " \n", - " \n", " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", - " \n", - " \n", - " \n", - " \n", " \n", - " \n", " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", - " \n", " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", "
vehicle_typevehicle_idvehicleclass_make_electricfuel-onlyhybridmodel.1_model_yearcylinders_fuelconsumption_city(l/100km)fuelconsumption_hwy(l/100km)fuelconsumption_comb(l/100km)co2emissions_(g/km)...consumption_city(kwh/100km)fuelconsumption_hwy(kwh/100km)fuelconsumption_comb(kwh/100km)fuelconsumption_city(le/100km)fuelconsumption_hwy(le/100km)fuelconsumption_comb(le/100km)range_(km)hybrid_in_fuelhybrid_in_electricaggregate_levels
0fuel-only_1full-sizeacuraintegra20234.07.96.37.2167...0.00.0121.00.00.00.00.00.0010
1alfa romeofuel-only_2full-sizeacuraintegra a-spec20234.08.16.57.4172...0.049.00.0
2aston martin0.080.00.0
3audi18.0495.011.0
4bentley0.085.05.0
5bmw36.0842.053.0
6bugatti0.013.00.0010
7buick2fuel-only_3full-sizeacuraintegra a-spec20234.08.96.57.8181...0.0166.00.0
8cadillac2.0286.05.0
9chevrolet12.01019.08.0
10chrysler0.0149.07.0
11dodge0.0385.00.0
12fiat0.086.00.0010
13ford33.01068.017.0
14genesis4.051.03fuel-only_4suv - smallacuramdx sh-awd20236.012.69.411.2263...0.0
15gmc0.0628.00.0
16honda0.0333.04.0
17hyundai20.0351.012.0
18infiniti0.0164.00.0
19jaguar4.0232.00.0010
20jeep4fuel-only_5suv - standardacuramdx sh-awd type s20236.013.811.212.4291...0.0393.05.0
21karma0.00.07.0
22kia26.0364.012.0
23lamborghini0.081.00.0
24land rover0.0174.00.0
25lexus2.0301.02.0
26lincoln010
..................................................................
13091electric_420suv - smallvolkswagenid.420230.0140.07.0
27lucid15.00.00.00.00...18.221.219.62.02.42.2336.0100
28maserati13092electric_421suv - smallvolkswagenid.4 pro20230.0108.00.0
29mazda2.0298.00.0
30mercedes-benz8.0744.09.0
31mini4.0340.06.0
32mitsubishi6.0150.06.0
33nissan20.0408.00.00...18.221.319.62.02.42.2443.0100
34polestar7.013093electric_422suv - smallvolkswagenid.4 awd pro20230.01.0
35porsche21.0665.022.0
36ram0.0164.00.0
37rivian10.00.00...20.122.621.22.32.52.4410.0100
13094electric_423suv - smallvolvoc40 recharge twin20230.0
38rolls-royce0.090.00.00.00...22.226.123.92.52.92.7364.0100
39scion13095electric_424suv - smallvolvoxc40 recharge twin20230.038.00.0
40smart10.011.00.0
41smart eq2.00.00.0
42srt0.04.00.0
43subaru1.0233.04.0
44suzuki0.024.00.0
45tesla143.00.00.0
46toyota2.0571.013.0
47volkswagen11.0328.00.0
48volvo5.0191.033.00.00...22.826.624.52.63.02.8359.0100
\n", + "

13096 rows × 38 columns

\n", "" ], "text/plain": [ - "vehicle_type make_ electric fuel-only hybrid\n", - "0 acura 0.0 121.0 0.0\n", - "1 alfa romeo 0.0 49.0 0.0\n", - "2 aston martin 0.0 80.0 0.0\n", - "3 audi 18.0 495.0 11.0\n", - "4 bentley 0.0 85.0 5.0\n", - "5 bmw 36.0 842.0 53.0\n", - "6 bugatti 0.0 13.0 0.0\n", - "7 buick 0.0 166.0 0.0\n", - "8 cadillac 2.0 286.0 5.0\n", - "9 chevrolet 12.0 1019.0 8.0\n", - "10 chrysler 0.0 149.0 7.0\n", - "11 dodge 0.0 385.0 0.0\n", - "12 fiat 0.0 86.0 0.0\n", - "13 ford 33.0 1068.0 17.0\n", - "14 genesis 4.0 51.0 0.0\n", - "15 gmc 0.0 628.0 0.0\n", - "16 honda 0.0 333.0 4.0\n", - "17 hyundai 20.0 351.0 12.0\n", - "18 infiniti 0.0 164.0 0.0\n", - "19 jaguar 4.0 232.0 0.0\n", - "20 jeep 0.0 393.0 5.0\n", - "21 karma 0.0 0.0 7.0\n", - "22 kia 26.0 364.0 12.0\n", - "23 lamborghini 0.0 81.0 0.0\n", - "24 land rover 0.0 174.0 0.0\n", - "25 lexus 2.0 301.0 2.0\n", - "26 lincoln 0.0 140.0 7.0\n", - "27 lucid 15.0 0.0 0.0\n", - "28 maserati 0.0 108.0 0.0\n", - "29 mazda 2.0 298.0 0.0\n", - "30 mercedes-benz 8.0 744.0 9.0\n", - "31 mini 4.0 340.0 6.0\n", - "32 mitsubishi 6.0 150.0 6.0\n", - "33 nissan 20.0 408.0 0.0\n", - "34 polestar 7.0 0.0 1.0\n", - "35 porsche 21.0 665.0 22.0\n", - "36 ram 0.0 164.0 0.0\n", - "37 rivian 10.0 0.0 0.0\n", - "38 rolls-royce 0.0 90.0 0.0\n", - "39 scion 0.0 38.0 0.0\n", - "40 smart 10.0 11.0 0.0\n", - "41 smart eq 2.0 0.0 0.0\n", - "42 srt 0.0 4.0 0.0\n", - "43 subaru 1.0 233.0 4.0\n", - "44 suzuki 0.0 24.0 0.0\n", - "45 tesla 143.0 0.0 0.0\n", - "46 toyota 2.0 571.0 13.0\n", - "47 volkswagen 11.0 328.0 0.0\n", - "48 volvo 5.0 191.0 33.0" + " vehicle_id vehicleclass_ make_ model.1_ \\\n", + "0 fuel-only_1 full-size acura integra \n", + "1 fuel-only_2 full-size acura integra a-spec \n", + "2 fuel-only_3 full-size acura integra a-spec \n", + "3 fuel-only_4 suv - small acura mdx sh-awd \n", + "4 fuel-only_5 suv - standard acura mdx sh-awd type s \n", + "... ... ... ... ... \n", + "13091 electric_420 suv - small volkswagen id.4 \n", + "13092 electric_421 suv - small volkswagen id.4 pro \n", + "13093 electric_422 suv - small volkswagen id.4 awd pro \n", + "13094 electric_423 suv - small volvo c40 recharge twin \n", + "13095 electric_424 suv - small volvo xc40 recharge twin \n", + "\n", + " model_year cylinders_ fuelconsumption_city(l/100km) \\\n", + "0 2023 4.0 7.9 \n", + "1 2023 4.0 8.1 \n", + "2 2023 4.0 8.9 \n", + "3 2023 6.0 12.6 \n", + "4 2023 6.0 13.8 \n", + "... ... ... ... \n", + "13091 2023 0.0 0.0 \n", + "13092 2023 0.0 0.0 \n", + "13093 2023 0.0 0.0 \n", + "13094 2023 0.0 0.0 \n", + "13095 2023 0.0 0.0 \n", + "\n", + " fuelconsumption_hwy(l/100km) fuelconsumption_comb(l/100km) \\\n", + "0 6.3 7.2 \n", + "1 6.5 7.4 \n", + "2 6.5 7.8 \n", + "3 9.4 11.2 \n", + "4 11.2 12.4 \n", + "... ... ... \n", + "13091 0.0 0.0 \n", + "13092 0.0 0.0 \n", + "13093 0.0 0.0 \n", + "13094 0.0 0.0 \n", + "13095 0.0 0.0 \n", + "\n", + " co2emissions_(g/km) ... consumption_city(kwh/100km) \\\n", + "0 167 ... 0.0 \n", + "1 172 ... 0.0 \n", + "2 181 ... 0.0 \n", + "3 263 ... 0.0 \n", + "4 291 ... 0.0 \n", + "... ... ... ... \n", + "13091 0 ... 18.2 \n", + "13092 0 ... 18.2 \n", + "13093 0 ... 20.1 \n", + "13094 0 ... 22.2 \n", + "13095 0 ... 22.8 \n", + "\n", + " fuelconsumption_hwy(kwh/100km) fuelconsumption_comb(kwh/100km) \\\n", + "0 0.0 0.0 \n", + "1 0.0 0.0 \n", + "2 0.0 0.0 \n", + "3 0.0 0.0 \n", + "4 0.0 0.0 \n", + "... ... ... \n", + "13091 21.2 19.6 \n", + "13092 21.3 19.6 \n", + "13093 22.6 21.2 \n", + "13094 26.1 23.9 \n", + "13095 26.6 24.5 \n", + "\n", + " fuelconsumption_city(le/100km) fuelconsumption_hwy(le/100km) \\\n", + "0 0.0 0.0 \n", + "1 0.0 0.0 \n", + "2 0.0 0.0 \n", + "3 0.0 0.0 \n", + "4 0.0 0.0 \n", + "... ... ... \n", + "13091 2.0 2.4 \n", + "13092 2.0 2.4 \n", + "13093 2.3 2.5 \n", + "13094 2.5 2.9 \n", + "13095 2.6 3.0 \n", + "\n", + " fuelconsumption_comb(le/100km) range_(km) hybrid_in_fuel \\\n", + "0 0.0 0.0 0 \n", + "1 0.0 0.0 0 \n", + "2 0.0 0.0 0 \n", + "3 0.0 0.0 0 \n", + "4 0.0 0.0 0 \n", + "... ... ... ... \n", + "13091 2.2 336.0 1 \n", + "13092 2.2 443.0 1 \n", + "13093 2.4 410.0 1 \n", + "13094 2.7 364.0 1 \n", + "13095 2.8 359.0 1 \n", + "\n", + " hybrid_in_electric aggregate_levels \n", + "0 1 0 \n", + "1 1 0 \n", + "2 1 0 \n", + "3 1 0 \n", + "4 1 0 \n", + "... ... ... \n", + "13091 0 0 \n", + "13092 0 0 \n", + "13093 0 0 \n", + "13094 0 0 \n", + "13095 0 0 \n", + "\n", + "[13096 rows x 38 columns]" ] }, - "execution_count": 77, + "execution_count": 108, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "vehicle_type_count = master_df.groupby('make_')['vehicle_type'].value_counts().unstack().reset_index().fillna(0)\n", - "\n", - "# Display the dataframe\n", - "vehicle_type_count\n" - ] - }, - { - "cell_type": "code", - "execution_count": 89, - "metadata": {}, - "outputs": [], - "source": [ - "make_total_avg_score_u = pd.DataFrame(master_df.groupby([\"make_\"])['predicted_co2_rating'].mean()).reset_index().rename(columns={'predicted_co2_rating':'avg_predicted_co2_rating_by_make'})\n", - "\n", - "make_total_avg_score_u.sort_values(by='avg_predicted_co2_rating_by_make', ascending=False, inplace=True)\n" - ] - }, - { - "cell_type": "code", - "execution_count": 68, - "metadata": {}, - "outputs": [], - "source": [ - "import numpy as np\n", - "\n", - "# Merge this with your current dataframe\n", - "master_df_d = pd.merge(master_df, total_models_df, on='make_', how='left')\n", - "\n" - ] - }, - { - "cell_type": "code", - "execution_count": 85, - "metadata": {}, - "outputs": [], - "source": [ - "# Then you can use numpy's average function to compute the weighted average\n", - "make_total_avg_score = master_df_d.groupby('make_').apply(lambda x: np.average(x['predicted_co2_rating'], \n", - " weights=x['total_models'])).reset_index().rename(columns={0:'weighted_avg_predicted_co2_rating_by_make'})\n", - "make_total_avg_score.sort_values(by='weighted_avg_predicted_co2_rating_by_make', ascending=False, inplace=True)\n", - "\n" + "master_df" ] }, { "cell_type": "code", - "execution_count": 88, + "execution_count": 140, "metadata": {}, "outputs": [ { "data": { - "text/html": [ - "
\n", - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", + "application/vnd.plotly.v1+json": { + "config": { + "plotlyServerURL": "https://plot.ly" + }, + "data": [ + { + "alignmentgroup": "True", + "hovertemplate": "vehicle_type=%{x}
count=%{y}", + "legendgroup": "", + "marker": { + "color": "#636efa", + "pattern": { + "shape": "" + } + }, + "name": "", + "offsetgroup": "", + "orientation": "v", + "showlegend": false, + "textposition": "auto", + "type": "bar", + "x": [ + "fuel-only", + "electric", + "hybrid" + ], + "xaxis": "x", + "y": [ + 12423, + 424, + 249 + ], + "yaxis": "y" + } + ], + "layout": { + "barmode": "relative", + "legend": { + "tracegroupgap": 0 + }, + "template": { + "data": { + "bar": [ + { + "error_x": { + "color": "#2a3f5f" + }, + "error_y": { + "color": "#2a3f5f" + }, + "marker": { + "line": { + "color": "#E5ECF6", + "width": 0.5 + }, + "pattern": { + "fillmode": "overlay", + "size": 10, + "solidity": 0.2 + } + }, + "type": "bar" + } + ], + "barpolar": [ + { + "marker": { + "line": { + "color": "#E5ECF6", + "width": 0.5 + }, + "pattern": { + "fillmode": "overlay", + "size": 10, + "solidity": 0.2 + } + }, + "type": "barpolar" + } + ], + "carpet": [ + { + "aaxis": { + "endlinecolor": "#2a3f5f", + "gridcolor": "white", + "linecolor": "white", + "minorgridcolor": "white", + "startlinecolor": "#2a3f5f" + }, + "baxis": { + "endlinecolor": "#2a3f5f", + "gridcolor": "white", + "linecolor": "white", + "minorgridcolor": "white", + "startlinecolor": "#2a3f5f" + }, + "type": "carpet" + } + ], + "choropleth": [ + { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + }, + "type": "choropleth" + } + ], + "contour": [ + { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + }, + "colorscale": [ + [ + 0, + "#0d0887" + ], + [ + 0.1111111111111111, + "#46039f" + ], + [ + 0.2222222222222222, + "#7201a8" + ], + [ + 0.3333333333333333, + "#9c179e" + ], + [ + 0.4444444444444444, + "#bd3786" + ], + [ + 0.5555555555555556, + "#d8576b" + ], + [ + 0.6666666666666666, + "#ed7953" + ], + [ + 0.7777777777777778, + "#fb9f3a" + ], + [ + 0.8888888888888888, + "#fdca26" + ], + [ + 1, + "#f0f921" + ] + ], + "type": "contour" + } + ], + "contourcarpet": [ + { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + }, + "type": "contourcarpet" + } + ], + "heatmap": [ + { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + }, + "colorscale": [ + [ + 0, + "#0d0887" + ], + [ + 0.1111111111111111, + "#46039f" + ], + [ + 0.2222222222222222, + "#7201a8" + ], + [ + 0.3333333333333333, + "#9c179e" + ], + [ + 0.4444444444444444, + "#bd3786" + ], + [ + 0.5555555555555556, + "#d8576b" + ], + [ + 0.6666666666666666, + "#ed7953" + ], + [ + 0.7777777777777778, + "#fb9f3a" + ], + [ + 0.8888888888888888, + "#fdca26" + ], + [ + 1, + "#f0f921" + ] + ], + "type": "heatmap" + } + ], + "heatmapgl": [ + { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + }, + "colorscale": [ + [ + 0, + "#0d0887" + ], + [ + 0.1111111111111111, + "#46039f" + ], + [ + 0.2222222222222222, + "#7201a8" + ], + [ + 0.3333333333333333, + "#9c179e" + ], + [ + 0.4444444444444444, + "#bd3786" + ], + [ + 0.5555555555555556, + "#d8576b" + ], + [ + 0.6666666666666666, + "#ed7953" + ], + [ + 0.7777777777777778, + "#fb9f3a" + ], + [ + 0.8888888888888888, + "#fdca26" + ], + [ + 1, + "#f0f921" + ] + ], + "type": "heatmapgl" + } + ], + "histogram": [ + { + "marker": { + "pattern": { + "fillmode": "overlay", + "size": 10, + "solidity": 0.2 + } + }, + "type": "histogram" + } + ], + "histogram2d": [ + { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + }, + "colorscale": [ + [ + 0, + "#0d0887" + ], + [ + 0.1111111111111111, + "#46039f" + ], + [ + 0.2222222222222222, + "#7201a8" + ], + [ + 0.3333333333333333, + "#9c179e" + ], + [ + 0.4444444444444444, + "#bd3786" + ], + [ + 0.5555555555555556, + "#d8576b" + ], + [ + 0.6666666666666666, + "#ed7953" + ], + [ + 0.7777777777777778, + "#fb9f3a" + ], + [ + 0.8888888888888888, + "#fdca26" + ], + [ + 1, + "#f0f921" + ] + ], + "type": "histogram2d" + } + ], + "histogram2dcontour": [ + { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + }, + "colorscale": [ + [ + 0, + "#0d0887" + ], + [ + 0.1111111111111111, + "#46039f" + ], + [ + 0.2222222222222222, + "#7201a8" + ], + [ + 0.3333333333333333, + "#9c179e" + ], + [ + 0.4444444444444444, + "#bd3786" + ], + [ + 0.5555555555555556, + "#d8576b" + ], + [ + 0.6666666666666666, + "#ed7953" + ], + [ + 0.7777777777777778, + "#fb9f3a" + ], + [ + 0.8888888888888888, + "#fdca26" + ], + [ + 1, + "#f0f921" + ] + ], + "type": "histogram2dcontour" + } + ], + "mesh3d": [ + { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + }, + "type": "mesh3d" + } + ], + "parcoords": [ + { + "line": { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + } + }, + "type": "parcoords" + } + ], + "pie": [ + { + "automargin": true, + "type": "pie" + } + ], + "scatter": [ + { + "fillpattern": { + "fillmode": "overlay", + "size": 10, + "solidity": 0.2 + }, + "type": "scatter" + } + ], + "scatter3d": [ + { + "line": { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + } + }, + "marker": { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + } + }, + "type": "scatter3d" + } + ], + "scattercarpet": [ + { + "marker": { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + } + }, + "type": "scattercarpet" + } + ], + "scattergeo": [ + { + "marker": { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + } + }, + "type": "scattergeo" + } + ], + "scattergl": [ + { + "marker": { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + } + }, + "type": "scattergl" + } + ], + "scattermapbox": [ + { + "marker": { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + } + }, + "type": "scattermapbox" + } + ], + "scatterpolar": [ + { + "marker": { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + } + }, + "type": "scatterpolar" + } + ], + "scatterpolargl": [ + { + "marker": { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + } + }, + "type": "scatterpolargl" + } + ], + "scatterternary": [ + { + "marker": { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + } + }, + "type": "scatterternary" + } + ], + "surface": [ + { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + }, + "colorscale": [ + [ + 0, + "#0d0887" + ], + [ + 0.1111111111111111, + "#46039f" + ], + [ + 0.2222222222222222, + "#7201a8" + ], + [ + 0.3333333333333333, + "#9c179e" + ], + [ + 0.4444444444444444, + "#bd3786" + ], + [ + 0.5555555555555556, + "#d8576b" + ], + [ + 0.6666666666666666, + "#ed7953" + ], + [ + 0.7777777777777778, + "#fb9f3a" + ], + [ + 0.8888888888888888, + "#fdca26" + ], + [ + 1, + "#f0f921" + ] + ], + "type": "surface" + } + ], + "table": [ + { + "cells": { + "fill": { + "color": "#EBF0F8" + }, + "line": { + "color": "white" + } + }, + "header": { + "fill": { + "color": "#C8D4E3" + }, + "line": { + "color": "white" + } + }, + "type": "table" + } + ] + }, + "layout": { + "annotationdefaults": { + "arrowcolor": "#2a3f5f", + "arrowhead": 0, + "arrowwidth": 1 + }, + "autotypenumbers": "strict", + "coloraxis": { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + } + }, + "colorscale": { + "diverging": [ + [ + 0, + "#8e0152" + ], + [ + 0.1, + "#c51b7d" + ], + [ + 0.2, + "#de77ae" + ], + [ + 0.3, + "#f1b6da" + ], + [ + 0.4, + "#fde0ef" + ], + [ + 0.5, + "#f7f7f7" + ], + [ + 0.6, + "#e6f5d0" + ], + [ + 0.7, + "#b8e186" + ], + [ + 0.8, + "#7fbc41" + ], + [ + 0.9, + "#4d9221" + ], + [ + 1, + "#276419" + ] + ], + "sequential": [ + [ + 0, + "#0d0887" + ], + [ + 0.1111111111111111, + "#46039f" + ], + [ + 0.2222222222222222, + "#7201a8" + ], + [ + 0.3333333333333333, + "#9c179e" + ], + [ + 0.4444444444444444, + "#bd3786" + ], + [ + 0.5555555555555556, + "#d8576b" + ], + [ + 0.6666666666666666, + "#ed7953" + ], + [ + 0.7777777777777778, + "#fb9f3a" + ], + [ + 0.8888888888888888, + "#fdca26" + ], + [ + 1, + "#f0f921" + ] + ], + "sequentialminus": [ + [ + 0, + "#0d0887" + ], + [ + 0.1111111111111111, + "#46039f" + ], + [ + 0.2222222222222222, + "#7201a8" + ], + [ + 0.3333333333333333, + "#9c179e" + ], + [ + 0.4444444444444444, + "#bd3786" + ], + [ + 0.5555555555555556, + "#d8576b" + ], + [ + 0.6666666666666666, + "#ed7953" + ], + [ + 0.7777777777777778, + "#fb9f3a" + ], + [ + 0.8888888888888888, + "#fdca26" + ], + [ + 1, + "#f0f921" + ] + ] + }, + "colorway": [ + "#636efa", + "#EF553B", + "#00cc96", + "#ab63fa", + "#FFA15A", + "#19d3f3", + "#FF6692", + "#B6E880", + "#FF97FF", + "#FECB52" + ], + "font": { + "color": "#2a3f5f" + }, + "geo": { + "bgcolor": "white", + "lakecolor": "white", + "landcolor": "#E5ECF6", + "showlakes": true, + "showland": true, + "subunitcolor": "white" + }, + "hoverlabel": { + "align": "left" + }, + "hovermode": "closest", + "mapbox": { + "style": "light" + }, + "paper_bgcolor": "white", + "plot_bgcolor": "#E5ECF6", + "polar": { + "angularaxis": { + "gridcolor": "white", + "linecolor": "white", + "ticks": "" + }, + "bgcolor": "#E5ECF6", + "radialaxis": { + "gridcolor": "white", + "linecolor": "white", + "ticks": "" + } + }, + "scene": { + "xaxis": { + "backgroundcolor": "#E5ECF6", + "gridcolor": "white", + "gridwidth": 2, + "linecolor": "white", + "showbackground": true, + "ticks": "", + "zerolinecolor": "white" + }, + "yaxis": { + "backgroundcolor": "#E5ECF6", + "gridcolor": "white", + "gridwidth": 2, + "linecolor": "white", + "showbackground": true, + "ticks": "", + "zerolinecolor": "white" + }, + "zaxis": { + "backgroundcolor": "#E5ECF6", + "gridcolor": "white", + "gridwidth": 2, + "linecolor": "white", + "showbackground": true, + "ticks": "", + "zerolinecolor": "white" + } + }, + "shapedefaults": { + "line": { + "color": "#2a3f5f" + } + }, + "ternary": { + "aaxis": { + "gridcolor": "white", + "linecolor": "white", + "ticks": "" + }, + "baxis": { + "gridcolor": "white", + "linecolor": "white", + "ticks": "" + }, + "bgcolor": "#E5ECF6", + "caxis": { + "gridcolor": "white", + "linecolor": "white", + "ticks": "" + } + }, + "title": { + "x": 0.05 + }, + "xaxis": { + "automargin": true, + "gridcolor": "white", + "linecolor": "white", + "ticks": "", + "title": { + "standoff": 15 + }, + "zerolinecolor": "white", + "zerolinewidth": 2 + }, + "yaxis": { + "automargin": true, + "gridcolor": "white", + "linecolor": "white", + "ticks": "", + "title": { + "standoff": 15 + }, + "zerolinecolor": "white", + "zerolinewidth": 2 + } + } + }, + "title": { + "text": "Vehicle Type Count" + }, + "xaxis": { + "anchor": "y", + "domain": [ + 0, + 1 + ], + "title": { + "text": "vehicle_type" + } + }, + "yaxis": { + "anchor": "x", + "domain": [ + 0, + 1 + ], + "title": { + "text": "count" + } + } + } + } + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "vehicle_type_count = master_df['vehicle_type'].value_counts().reset_index()\n", + "vehicle_type_count.columns = ['vehicle_type', 'count']\n", + "\n", + "\n", + "\n", + "vehicle_type_count\n", + "\n", + "px.bar(vehicle_type_count, x='vehicle_type', y='count', title='Vehicle Type Count')" + ] + }, + { + "cell_type": "code", + "execution_count": 117, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "0" + ] + }, + "execution_count": 117, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# count total number of electric vehicles\n", + "electric_vehicles = master_df[master_df['fuel_type'] == 'Electricity']\n", + "electric_vehicles_count = electric_vehicles['fuel_type'].count()\n", + "\n", + "electric_vehicles_count" + ] + }, + { + "cell_type": "code", + "execution_count": 89, + "metadata": {}, + "outputs": [], + "source": [ + "make_total_avg_score_u = pd.DataFrame(master_df.groupby([\"make_\"])['predicted_co2_rating'].mean()).reset_index().rename(columns={'predicted_co2_rating':'avg_predicted_co2_rating_by_make'})\n", + "\n", + "make_total_avg_score_u.sort_values(by='avg_predicted_co2_rating_by_make', ascending=False, inplace=True)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 68, + "metadata": {}, + "outputs": [], + "source": [ + "import numpy as np\n", + "\n", + "# Merge this with your current dataframe\n", + "master_df_d = pd.merge(master_df, total_models_df, on='make_', how='left')\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": 85, + "metadata": {}, + "outputs": [], + "source": [ + "# Then you can use numpy's average function to compute the weighted average\n", + "make_total_avg_score = master_df_d.groupby('make_').apply(lambda x: np.average(x['predicted_co2_rating'], \n", + " weights=x['total_models'])).reset_index().rename(columns={0:'weighted_avg_predicted_co2_rating_by_make'})\n", + "make_total_avg_score.sort_values(by='weighted_avg_predicted_co2_rating_by_make', ascending=False, inplace=True)\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": 103, + "metadata": {}, + "outputs": [], + "source": [ + "weighted_avg_df = pd.merge(total_models_df, make_total_avg_score, on='make_', how='left')\n", + "\n", + "# sort the dataframe by the weighted average\n", + "weighted_avg_df.sort_values(by='weighted_avg_predicted_co2_rating_by_make', ascending=False, inplace=True)\n", + "\n", + "df = pd.merge(weighted_avg_df, vehicle_type_count, on='make_', how='left').sort_values(by='weighted_avg_predicted_co2_rating_by_make', ascending=False)" + ] + }, + { + "cell_type": "code", + "execution_count": 107, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "
make_total_modelsweighted_avg_predicted_co2_rating_by_make
37rivian1010.000000
41smart eq210.000000
27lucid1510.000000
34polestar610.000000
21karma510.000000
45tesla6110.000000
40smart49.238095
12fiat136.627907
16honda446.560831
31mini356.451429
17hyundai646.441253
22kia556.395522
32mitsubishi186.370370
39scion66.342105
29mazda456.306667
47volkswagen456.032448
46toyota975.880546
\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", + " \n", + " \n", " \n", - " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", - " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", - " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", - " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", - " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", - " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", - " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", - " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", - " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", " \n", " \n", - " \n", - " \n", + " \n", + " \n", + " \n", " \n", " \n", - " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", " \n", " \n", - " \n", - " \n", + " \n", + " \n", + " \n", " \n", " \n", - " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", - " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", " \n", " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", " \n", " \n", - " \n", - " \n", + " \n", + " \n", + " \n", " \n", " \n", - " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", - " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", - " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", - " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", - " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", - " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", - " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", - " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", - " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", - " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", - " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", - " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", - " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", - " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", - " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", - " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", "
vehicle_typemake_electricfuel-onlyhybrid
48volvo955.8558950acura0.0121.00.0
44suzuki155.8333331alfa romeo0.049.00.0
43subaru235.6722692aston martin0.080.00.0
33nissan535.4649533audi18.0495.011.0
7buick285.2349404bentley0.085.05.0
0acura315.1900835bmw36.0842.053.0
25lexus675.1573776bugatti0.013.00.0
1alfa romeo115.0612247buick0.0166.00.0
5bmw2654.9806668cadillac2.0286.05.0
9chevrolet12.01019.08.0
10chrysler314.9166670.0149.07.0
3audi1554.91603111dodge0.0385.00.0
12fiat0.086.00.0
13ford1554.63595733.01068.017.0
35porsche1144.61581914genesis4.051.00.0
26lincoln244.60544215gmc0.0628.00.0
16honda0.0333.04.0
17hyundai20.0351.012.0
18infiniti464.5731710.0164.00.0
19jaguar4.0232.00.0
20jeep664.5728640.0393.05.0
14genesis114.45454521karma0.00.07.0
8cadillac524.45392522kia26.0364.012.0
23lamborghini0.081.00.0
24land rover0.0174.00.0
25lexus2.0301.02.0
26lincoln0.0140.07.0
27lucid15.00.00.0
28maserati0.0108.00.0
29mazda2.0298.00.0
30mercedes-benz8.0744.09.0
31mini4.0340.06.0
32mitsubishi6.0150.06.0
33nissan20.0408.00.0
34polestar7.00.01.0
19jaguar894.39406835porsche21.0665.022.0
9chevrolet1284.35322436ram0.0164.00.0
30mercedes-benz2914.25492837rivian10.00.00.0
11dodge564.09350638rolls-royce0.090.00.0
24land rover773.72413839scion0.038.00.0
36ram283.67682940smart10.011.00.0
15gmc793.37101941smart eq2.00.00.0
28maserati323.10185242srt0.04.00.0
2aston martin222.67500043subaru1.0233.04.0
4bentley212.53333344suzuki0.024.00.0
42srt42.00000045tesla143.00.00.0
23lamborghini391.56790146toyota2.0571.013.0
38rolls-royce151.53333347volkswagen11.0328.00.0
6bugatti51.00000048volvo5.0191.033.0
\n", "
" ], "text/plain": [ - " make_ total_models weighted_avg_predicted_co2_rating_by_make\n", - "37 rivian 10 10.000000\n", - "41 smart eq 2 10.000000\n", - "27 lucid 15 10.000000\n", - "34 polestar 6 10.000000\n", - "21 karma 5 10.000000\n", - "45 tesla 61 10.000000\n", - "40 smart 4 9.238095\n", - "12 fiat 13 6.627907\n", - "16 honda 44 6.560831\n", - "31 mini 35 6.451429\n", - "17 hyundai 64 6.441253\n", - "22 kia 55 6.395522\n", - "32 mitsubishi 18 6.370370\n", - "39 scion 6 6.342105\n", - "29 mazda 45 6.306667\n", - "47 volkswagen 45 6.032448\n", - "46 toyota 97 5.880546\n", - "48 volvo 95 5.855895\n", - "44 suzuki 15 5.833333\n", - "43 subaru 23 5.672269\n", - "33 nissan 53 5.464953\n", - "7 buick 28 5.234940\n", - "0 acura 31 5.190083\n", - "25 lexus 67 5.157377\n", - "1 alfa romeo 11 5.061224\n", - "5 bmw 265 4.980666\n", - "10 chrysler 31 4.916667\n", - "3 audi 155 4.916031\n", - "13 ford 155 4.635957\n", - "35 porsche 114 4.615819\n", - "26 lincoln 24 4.605442\n", - "18 infiniti 46 4.573171\n", - "20 jeep 66 4.572864\n", - "14 genesis 11 4.454545\n", - "8 cadillac 52 4.453925\n", - "19 jaguar 89 4.394068\n", - "9 chevrolet 128 4.353224\n", - "30 mercedes-benz 291 4.254928\n", - "11 dodge 56 4.093506\n", - "24 land rover 77 3.724138\n", - "36 ram 28 3.676829\n", - "15 gmc 79 3.371019\n", - "28 maserati 32 3.101852\n", - "2 aston martin 22 2.675000\n", - "4 bentley 21 2.533333\n", - "42 srt 4 2.000000\n", - "23 lamborghini 39 1.567901\n", - "38 rolls-royce 15 1.533333\n", - "6 bugatti 5 1.000000" + "vehicle_type make_ electric fuel-only hybrid\n", + "0 acura 0.0 121.0 0.0\n", + "1 alfa romeo 0.0 49.0 0.0\n", + "2 aston martin 0.0 80.0 0.0\n", + "3 audi 18.0 495.0 11.0\n", + "4 bentley 0.0 85.0 5.0\n", + "5 bmw 36.0 842.0 53.0\n", + "6 bugatti 0.0 13.0 0.0\n", + "7 buick 0.0 166.0 0.0\n", + "8 cadillac 2.0 286.0 5.0\n", + "9 chevrolet 12.0 1019.0 8.0\n", + "10 chrysler 0.0 149.0 7.0\n", + "11 dodge 0.0 385.0 0.0\n", + "12 fiat 0.0 86.0 0.0\n", + "13 ford 33.0 1068.0 17.0\n", + "14 genesis 4.0 51.0 0.0\n", + "15 gmc 0.0 628.0 0.0\n", + "16 honda 0.0 333.0 4.0\n", + "17 hyundai 20.0 351.0 12.0\n", + "18 infiniti 0.0 164.0 0.0\n", + "19 jaguar 4.0 232.0 0.0\n", + "20 jeep 0.0 393.0 5.0\n", + "21 karma 0.0 0.0 7.0\n", + "22 kia 26.0 364.0 12.0\n", + "23 lamborghini 0.0 81.0 0.0\n", + "24 land rover 0.0 174.0 0.0\n", + "25 lexus 2.0 301.0 2.0\n", + "26 lincoln 0.0 140.0 7.0\n", + "27 lucid 15.0 0.0 0.0\n", + "28 maserati 0.0 108.0 0.0\n", + "29 mazda 2.0 298.0 0.0\n", + "30 mercedes-benz 8.0 744.0 9.0\n", + "31 mini 4.0 340.0 6.0\n", + "32 mitsubishi 6.0 150.0 6.0\n", + "33 nissan 20.0 408.0 0.0\n", + "34 polestar 7.0 0.0 1.0\n", + "35 porsche 21.0 665.0 22.0\n", + "36 ram 0.0 164.0 0.0\n", + "37 rivian 10.0 0.0 0.0\n", + "38 rolls-royce 0.0 90.0 0.0\n", + "39 scion 0.0 38.0 0.0\n", + "40 smart 10.0 11.0 0.0\n", + "41 smart eq 2.0 0.0 0.0\n", + "42 srt 0.0 4.0 0.0\n", + "43 subaru 1.0 233.0 4.0\n", + "44 suzuki 0.0 24.0 0.0\n", + "45 tesla 143.0 0.0 0.0\n", + "46 toyota 2.0 571.0 13.0\n", + "47 volkswagen 11.0 328.0 0.0\n", + "48 volvo 5.0 191.0 33.0" ] }, - "execution_count": 88, + "execution_count": 107, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "vehicle_type_count" + ] + }, + { + "cell_type": "code", + "execution_count": 106, + "metadata": {}, + "outputs": [ + { + "data": { + "application/vnd.plotly.v1+json": { + "config": { + "plotlyServerURL": "https://plot.ly" + }, + "data": [ + { + "marker": { + "color": "rgb(26, 118, 255)" + }, + "name": "Electric", + "type": "bar", + "x": [ + "bmw" + ], + "y": [ + 36 + ] + }, + { + "marker": { + "color": "rgb(55, 83, 109)" + }, + "name": "Fuel-only", + "type": "bar", + "x": [ + "bmw" + ], + "y": [ + 842 + ] + }, + { + "marker": { + "color": "rgb(26, 188, 156)" + }, + "name": "Hybrid", + "type": "bar", + "x": [ + "bmw" + ], + "y": [ + 53 + ] + } + ], + "layout": { + "barmode": "stack", + "font": { + "color": "white" + }, + "paper_bgcolor": "#003f5c", + "plot_bgcolor": "#003f5c", + "template": { + "data": { + "bar": [ + { + "error_x": { + "color": "#2a3f5f" + }, + "error_y": { + "color": "#2a3f5f" + }, + "marker": { + "line": { + "color": "#E5ECF6", + "width": 0.5 + }, + "pattern": { + "fillmode": "overlay", + "size": 10, + "solidity": 0.2 + } + }, + "type": "bar" + } + ], + "barpolar": [ + { + "marker": { + "line": { + "color": "#E5ECF6", + "width": 0.5 + }, + "pattern": { + "fillmode": "overlay", + "size": 10, + "solidity": 0.2 + } + }, + "type": "barpolar" + } + ], + "carpet": [ + { + "aaxis": { + "endlinecolor": "#2a3f5f", + "gridcolor": "white", + "linecolor": "white", + "minorgridcolor": "white", + "startlinecolor": "#2a3f5f" + }, + "baxis": { + "endlinecolor": "#2a3f5f", + "gridcolor": "white", + "linecolor": "white", + "minorgridcolor": "white", + "startlinecolor": "#2a3f5f" + }, + "type": "carpet" + } + ], + "choropleth": [ + { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + }, + "type": "choropleth" + } + ], + "contour": [ + { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + }, + "colorscale": [ + [ + 0, + "#0d0887" + ], + [ + 0.1111111111111111, + "#46039f" + ], + [ + 0.2222222222222222, + "#7201a8" + ], + [ + 0.3333333333333333, + "#9c179e" + ], + [ + 0.4444444444444444, + "#bd3786" + ], + [ + 0.5555555555555556, + "#d8576b" + ], + [ + 0.6666666666666666, + "#ed7953" + ], + [ + 0.7777777777777778, + "#fb9f3a" + ], + [ + 0.8888888888888888, + "#fdca26" + ], + [ + 1, + "#f0f921" + ] + ], + "type": "contour" + } + ], + "contourcarpet": [ + { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + }, + "type": "contourcarpet" + } + ], + "heatmap": [ + { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + }, + "colorscale": [ + [ + 0, + "#0d0887" + ], + [ + 0.1111111111111111, + "#46039f" + ], + [ + 0.2222222222222222, + "#7201a8" + ], + [ + 0.3333333333333333, + "#9c179e" + ], + [ + 0.4444444444444444, + "#bd3786" + ], + [ + 0.5555555555555556, + "#d8576b" + ], + [ + 0.6666666666666666, + "#ed7953" + ], + [ + 0.7777777777777778, + "#fb9f3a" + ], + [ + 0.8888888888888888, + "#fdca26" + ], + [ + 1, + "#f0f921" + ] + ], + "type": "heatmap" + } + ], + "heatmapgl": [ + { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + }, + "colorscale": [ + [ + 0, + "#0d0887" + ], + [ + 0.1111111111111111, + "#46039f" + ], + [ + 0.2222222222222222, + "#7201a8" + ], + [ + 0.3333333333333333, + "#9c179e" + ], + [ + 0.4444444444444444, + "#bd3786" + ], + [ + 0.5555555555555556, + "#d8576b" + ], + [ + 0.6666666666666666, + "#ed7953" + ], + [ + 0.7777777777777778, + "#fb9f3a" + ], + [ + 0.8888888888888888, + "#fdca26" + ], + [ + 1, + "#f0f921" + ] + ], + "type": "heatmapgl" + } + ], + "histogram": [ + { + "marker": { + "pattern": { + "fillmode": "overlay", + "size": 10, + "solidity": 0.2 + } + }, + "type": "histogram" + } + ], + "histogram2d": [ + { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + }, + "colorscale": [ + [ + 0, + "#0d0887" + ], + [ + 0.1111111111111111, + "#46039f" + ], + [ + 0.2222222222222222, + "#7201a8" + ], + [ + 0.3333333333333333, + "#9c179e" + ], + [ + 0.4444444444444444, + "#bd3786" + ], + [ + 0.5555555555555556, + "#d8576b" + ], + [ + 0.6666666666666666, + "#ed7953" + ], + [ + 0.7777777777777778, + "#fb9f3a" + ], + [ + 0.8888888888888888, + "#fdca26" + ], + [ + 1, + "#f0f921" + ] + ], + "type": "histogram2d" + } + ], + "histogram2dcontour": [ + { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + }, + "colorscale": [ + [ + 0, + "#0d0887" + ], + [ + 0.1111111111111111, + "#46039f" + ], + [ + 0.2222222222222222, + "#7201a8" + ], + [ + 0.3333333333333333, + "#9c179e" + ], + [ + 0.4444444444444444, + "#bd3786" + ], + [ + 0.5555555555555556, + "#d8576b" + ], + [ + 0.6666666666666666, + "#ed7953" + ], + [ + 0.7777777777777778, + "#fb9f3a" + ], + [ + 0.8888888888888888, + "#fdca26" + ], + [ + 1, + "#f0f921" + ] + ], + "type": "histogram2dcontour" + } + ], + "mesh3d": [ + { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + }, + "type": "mesh3d" + } + ], + "parcoords": [ + { + "line": { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + } + }, + "type": "parcoords" + } + ], + "pie": [ + { + "automargin": true, + "type": "pie" + } + ], + "scatter": [ + { + "fillpattern": { + "fillmode": "overlay", + "size": 10, + "solidity": 0.2 + }, + "type": "scatter" + } + ], + "scatter3d": [ + { + "line": { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + } + }, + "marker": { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + } + }, + "type": "scatter3d" + } + ], + "scattercarpet": [ + { + "marker": { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + } + }, + "type": "scattercarpet" + } + ], + "scattergeo": [ + { + "marker": { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + } + }, + "type": "scattergeo" + } + ], + "scattergl": [ + { + "marker": { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + } + }, + "type": "scattergl" + } + ], + "scattermapbox": [ + { + "marker": { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + } + }, + "type": "scattermapbox" + } + ], + "scatterpolar": [ + { + "marker": { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + } + }, + "type": "scatterpolar" + } + ], + "scatterpolargl": [ + { + "marker": { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + } + }, + "type": "scatterpolargl" + } + ], + "scatterternary": [ + { + "marker": { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + } + }, + "type": "scatterternary" + } + ], + "surface": [ + { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + }, + "colorscale": [ + [ + 0, + "#0d0887" + ], + [ + 0.1111111111111111, + "#46039f" + ], + [ + 0.2222222222222222, + "#7201a8" + ], + [ + 0.3333333333333333, + "#9c179e" + ], + [ + 0.4444444444444444, + "#bd3786" + ], + [ + 0.5555555555555556, + "#d8576b" + ], + [ + 0.6666666666666666, + "#ed7953" + ], + [ + 0.7777777777777778, + "#fb9f3a" + ], + [ + 0.8888888888888888, + "#fdca26" + ], + [ + 1, + "#f0f921" + ] + ], + "type": "surface" + } + ], + "table": [ + { + "cells": { + "fill": { + "color": "#EBF0F8" + }, + "line": { + "color": "white" + } + }, + "header": { + "fill": { + "color": "#C8D4E3" + }, + "line": { + "color": "white" + } + }, + "type": "table" + } + ] + }, + "layout": { + "annotationdefaults": { + "arrowcolor": "#2a3f5f", + "arrowhead": 0, + "arrowwidth": 1 + }, + "autotypenumbers": "strict", + "coloraxis": { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + } + }, + "colorscale": { + "diverging": [ + [ + 0, + "#8e0152" + ], + [ + 0.1, + "#c51b7d" + ], + [ + 0.2, + "#de77ae" + ], + [ + 0.3, + "#f1b6da" + ], + [ + 0.4, + "#fde0ef" + ], + [ + 0.5, + "#f7f7f7" + ], + [ + 0.6, + "#e6f5d0" + ], + [ + 0.7, + "#b8e186" + ], + [ + 0.8, + "#7fbc41" + ], + [ + 0.9, + "#4d9221" + ], + [ + 1, + "#276419" + ] + ], + "sequential": [ + [ + 0, + "#0d0887" + ], + [ + 0.1111111111111111, + "#46039f" + ], + [ + 0.2222222222222222, + "#7201a8" + ], + [ + 0.3333333333333333, + "#9c179e" + ], + [ + 0.4444444444444444, + "#bd3786" + ], + [ + 0.5555555555555556, + "#d8576b" + ], + [ + 0.6666666666666666, + "#ed7953" + ], + [ + 0.7777777777777778, + "#fb9f3a" + ], + [ + 0.8888888888888888, + "#fdca26" + ], + [ + 1, + "#f0f921" + ] + ], + "sequentialminus": [ + [ + 0, + "#0d0887" + ], + [ + 0.1111111111111111, + "#46039f" + ], + [ + 0.2222222222222222, + "#7201a8" + ], + [ + 0.3333333333333333, + "#9c179e" + ], + [ + 0.4444444444444444, + "#bd3786" + ], + [ + 0.5555555555555556, + "#d8576b" + ], + [ + 0.6666666666666666, + "#ed7953" + ], + [ + 0.7777777777777778, + "#fb9f3a" + ], + [ + 0.8888888888888888, + "#fdca26" + ], + [ + 1, + "#f0f921" + ] + ] + }, + "colorway": [ + "#636efa", + "#EF553B", + "#00cc96", + "#ab63fa", + "#FFA15A", + "#19d3f3", + "#FF6692", + "#B6E880", + "#FF97FF", + "#FECB52" + ], + "font": { + "color": "#2a3f5f" + }, + "geo": { + "bgcolor": "white", + "lakecolor": "white", + "landcolor": "#E5ECF6", + "showlakes": true, + "showland": true, + "subunitcolor": "white" + }, + "hoverlabel": { + "align": "left" + }, + "hovermode": "closest", + "mapbox": { + "style": "light" + }, + "paper_bgcolor": "white", + "plot_bgcolor": "#E5ECF6", + "polar": { + "angularaxis": { + "gridcolor": "white", + "linecolor": "white", + "ticks": "" + }, + "bgcolor": "#E5ECF6", + "radialaxis": { + "gridcolor": "white", + "linecolor": "white", + "ticks": "" + } + }, + "scene": { + "xaxis": { + "backgroundcolor": "#E5ECF6", + "gridcolor": "white", + "gridwidth": 2, + "linecolor": "white", + "showbackground": true, + "ticks": "", + "zerolinecolor": "white" + }, + "yaxis": { + "backgroundcolor": "#E5ECF6", + "gridcolor": "white", + "gridwidth": 2, + "linecolor": "white", + "showbackground": true, + "ticks": "", + "zerolinecolor": "white" + }, + "zaxis": { + "backgroundcolor": "#E5ECF6", + "gridcolor": "white", + "gridwidth": 2, + "linecolor": "white", + "showbackground": true, + "ticks": "", + "zerolinecolor": "white" + } + }, + "shapedefaults": { + "line": { + "color": "#2a3f5f" + } + }, + "ternary": { + "aaxis": { + "gridcolor": "white", + "linecolor": "white", + "ticks": "" + }, + "baxis": { + "gridcolor": "white", + "linecolor": "white", + "ticks": "" + }, + "bgcolor": "#E5ECF6", + "caxis": { + "gridcolor": "white", + "linecolor": "white", + "ticks": "" + } + }, + "title": { + "x": 0.05 + }, + "xaxis": { + "automargin": true, + "gridcolor": "white", + "linecolor": "white", + "ticks": "", + "title": { + "standoff": 15 + }, + "zerolinecolor": "white", + "zerolinewidth": 2 + }, + "yaxis": { + "automargin": true, + "gridcolor": "white", + "linecolor": "white", + "ticks": "", + "title": { + "standoff": 15 + }, + "zerolinecolor": "white", + "zerolinewidth": 2 + } + } + }, + "title": { + "text": "Number of Vehicle Types for BMW", + "x": 0.5 + }, + "xaxis": { + "showgrid": false, + "title": { + "text": "Make" + } + }, + "yaxis": { + "showgrid": false, + "title": { + "text": "Number of Vehicles" + } + } + } + } + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "make = 'bmw'\n", + "colors = {\n", + " 'background': '#003f5c',\n", + " 'text': 'white'\n", + "}\n", + "\n", + "df_filtered = df[df['make_']==make]\n", + "\n", + "fig = go.Figure(data=[\n", + " go.Bar(name='Electric', x=df_filtered['make_'], y=df_filtered['electric'], marker_color='rgb(26, 118, 255)'),\n", + " go.Bar(name='Fuel-only', x=df_filtered['make_'], y=df_filtered['fuel-only'], marker_color='rgb(55, 83, 109)'),\n", + " go.Bar(name='Hybrid', x=df_filtered['make_'], y=df_filtered['hybrid'], marker_color='rgb(26, 188, 156)')\n", + " ])\n", + "\n", + "# Change the bar mode\n", + "fig.update_layout(\n", + " barmode='stack',\n", + " title=f'Number of Vehicle Types for {make.upper()}',\n", + " title_x=0.5,\n", + " xaxis=dict(title='Make'),\n", + " yaxis=dict(title='Number of Vehicles'),\n", + " plot_bgcolor=colors['background'],\n", + " paper_bgcolor=colors['background'],\n", + " font_color=colors['text'],\n", + " xaxis_showgrid=False,\n", + " yaxis_showgrid=False\n", + ")" + ] + }, + { + "cell_type": "code", + "execution_count": 98, + "metadata": {}, + "outputs": [ + { + "data": { + "application/vnd.plotly.v1+json": { + "config": { + "plotlyServerURL": "https://plot.ly" + }, + "data": [ + { + "alignmentgroup": "True", + "hovertemplate": "make_=%{x}
weighted_avg_predicted_co2_rating_by_make=%{text}", + "legendgroup": "rivian", + "marker": { + "color": "rgb(251,180,174)", + "pattern": { + "shape": "" + } + }, + "name": "rivian", + "offsetgroup": "rivian", + "orientation": "v", + "showlegend": true, + "text": [ + 10 + ], + "textposition": "auto", + "type": "bar", + "x": [ + "rivian" + ], + "xaxis": "x", + "y": [ + 10 + ], + "yaxis": "y" + }, + { + "alignmentgroup": "True", + "hovertemplate": "make_=%{x}
weighted_avg_predicted_co2_rating_by_make=%{text}", + "legendgroup": "smart eq", + "marker": { + "color": "rgb(179,205,227)", + "pattern": { + "shape": "" + } + }, + "name": "smart eq", + "offsetgroup": "smart eq", + "orientation": "v", + "showlegend": true, + "text": [ + 10 + ], + "textposition": "auto", + "type": "bar", + "x": [ + "smart eq" + ], + "xaxis": "x", + "y": [ + 10 + ], + "yaxis": "y" + }, + { + "alignmentgroup": "True", + "hovertemplate": "make_=%{x}
weighted_avg_predicted_co2_rating_by_make=%{text}", + "legendgroup": "lucid", + "marker": { + "color": "rgb(204,235,197)", + "pattern": { + "shape": "" + } + }, + "name": "lucid", + "offsetgroup": "lucid", + "orientation": "v", + "showlegend": true, + "text": [ + 10 + ], + "textposition": "auto", + "type": "bar", + "x": [ + "lucid" + ], + "xaxis": "x", + "y": [ + 10 + ], + "yaxis": "y" + }, + { + "alignmentgroup": "True", + "hovertemplate": "make_=%{x}
weighted_avg_predicted_co2_rating_by_make=%{text}", + "legendgroup": "polestar", + "marker": { + "color": "rgb(222,203,228)", + "pattern": { + "shape": "" + } + }, + "name": "polestar", + "offsetgroup": "polestar", + "orientation": "v", + "showlegend": true, + "text": [ + 10 + ], + "textposition": "auto", + "type": "bar", + "x": [ + "polestar" + ], + "xaxis": "x", + "y": [ + 10 + ], + "yaxis": "y" + }, + { + "alignmentgroup": "True", + "hovertemplate": "make_=%{x}
weighted_avg_predicted_co2_rating_by_make=%{text}", + "legendgroup": "karma", + "marker": { + "color": "rgb(254,217,166)", + "pattern": { + "shape": "" + } + }, + "name": "karma", + "offsetgroup": "karma", + "orientation": "v", + "showlegend": true, + "text": [ + 10 + ], + "textposition": "auto", + "type": "bar", + "x": [ + "karma" + ], + "xaxis": "x", + "y": [ + 10 + ], + "yaxis": "y" + }, + { + "alignmentgroup": "True", + "hovertemplate": "make_=%{x}
weighted_avg_predicted_co2_rating_by_make=%{text}", + "legendgroup": "tesla", + "marker": { + "color": "rgb(255,255,204)", + "pattern": { + "shape": "" + } + }, + "name": "tesla", + "offsetgroup": "tesla", + "orientation": "v", + "showlegend": true, + "text": [ + 10 + ], + "textposition": "auto", + "type": "bar", + "x": [ + "tesla" + ], + "xaxis": "x", + "y": [ + 10 + ], + "yaxis": "y" + }, + { + "alignmentgroup": "True", + "hovertemplate": "make_=%{x}
weighted_avg_predicted_co2_rating_by_make=%{text}", + "legendgroup": "smart", + "marker": { + "color": "rgb(229,216,189)", + "pattern": { + "shape": "" + } + }, + "name": "smart", + "offsetgroup": "smart", + "orientation": "v", + "showlegend": true, + "text": [ + 9.238095238095237 + ], + "textposition": "auto", + "type": "bar", + "x": [ + "smart" + ], + "xaxis": "x", + "y": [ + 9.238095238095237 + ], + "yaxis": "y" + }, + { + "alignmentgroup": "True", + "hovertemplate": "make_=%{x}
weighted_avg_predicted_co2_rating_by_make=%{text}", + "legendgroup": "fiat", + "marker": { + "color": "rgb(253,218,236)", + "pattern": { + "shape": "" + } + }, + "name": "fiat", + "offsetgroup": "fiat", + "orientation": "v", + "showlegend": true, + "text": [ + 6.627906976744186 + ], + "textposition": "auto", + "type": "bar", + "x": [ + "fiat" + ], + "xaxis": "x", + "y": [ + 6.627906976744186 + ], + "yaxis": "y" + }, + { + "alignmentgroup": "True", + "hovertemplate": "make_=%{x}
weighted_avg_predicted_co2_rating_by_make=%{text}", + "legendgroup": "honda", + "marker": { + "color": "rgb(242,242,242)", + "pattern": { + "shape": "" + } + }, + "name": "honda", + "offsetgroup": "honda", + "orientation": "v", + "showlegend": true, + "text": [ + 6.560830860534125 + ], + "textposition": "auto", + "type": "bar", + "x": [ + "honda" + ], + "xaxis": "x", + "y": [ + 6.560830860534125 + ], + "yaxis": "y" + }, + { + "alignmentgroup": "True", + "hovertemplate": "make_=%{x}
weighted_avg_predicted_co2_rating_by_make=%{text}", + "legendgroup": "mini", + "marker": { + "color": "rgb(251,180,174)", + "pattern": { + "shape": "" + } + }, + "name": "mini", + "offsetgroup": "mini", + "orientation": "v", + "showlegend": true, + "text": [ + 6.451428571428571 + ], + "textposition": "auto", + "type": "bar", + "x": [ + "mini" + ], + "xaxis": "x", + "y": [ + 6.451428571428571 + ], + "yaxis": "y" + } + ], + "layout": { + "barmode": "relative", + "legend": { + "title": { + "text": "make_" + }, + "tracegroupgap": 0 + }, + "template": { + "data": { + "bar": [ + { + "error_x": { + "color": "#2a3f5f" + }, + "error_y": { + "color": "#2a3f5f" + }, + "marker": { + "line": { + "color": "#E5ECF6", + "width": 0.5 + }, + "pattern": { + "fillmode": "overlay", + "size": 10, + "solidity": 0.2 + } + }, + "type": "bar" + } + ], + "barpolar": [ + { + "marker": { + "line": { + "color": "#E5ECF6", + "width": 0.5 + }, + "pattern": { + "fillmode": "overlay", + "size": 10, + "solidity": 0.2 + } + }, + "type": "barpolar" + } + ], + "carpet": [ + { + "aaxis": { + "endlinecolor": "#2a3f5f", + "gridcolor": "white", + "linecolor": "white", + "minorgridcolor": "white", + "startlinecolor": "#2a3f5f" + }, + "baxis": { + "endlinecolor": "#2a3f5f", + "gridcolor": "white", + "linecolor": "white", + "minorgridcolor": "white", + "startlinecolor": "#2a3f5f" + }, + "type": "carpet" + } + ], + "choropleth": [ + { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + }, + "type": "choropleth" + } + ], + "contour": [ + { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + }, + "colorscale": [ + [ + 0, + "#0d0887" + ], + [ + 0.1111111111111111, + "#46039f" + ], + [ + 0.2222222222222222, + "#7201a8" + ], + [ + 0.3333333333333333, + "#9c179e" + ], + [ + 0.4444444444444444, + "#bd3786" + ], + [ + 0.5555555555555556, + "#d8576b" + ], + [ + 0.6666666666666666, + "#ed7953" + ], + [ + 0.7777777777777778, + "#fb9f3a" + ], + [ + 0.8888888888888888, + "#fdca26" + ], + [ + 1, + "#f0f921" + ] + ], + "type": "contour" + } + ], + "contourcarpet": [ + { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + }, + "type": "contourcarpet" + } + ], + "heatmap": [ + { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + }, + "colorscale": [ + [ + 0, + "#0d0887" + ], + [ + 0.1111111111111111, + "#46039f" + ], + [ + 0.2222222222222222, + "#7201a8" + ], + [ + 0.3333333333333333, + "#9c179e" + ], + [ + 0.4444444444444444, + "#bd3786" + ], + [ + 0.5555555555555556, + "#d8576b" + ], + [ + 0.6666666666666666, + "#ed7953" + ], + [ + 0.7777777777777778, + "#fb9f3a" + ], + [ + 0.8888888888888888, + "#fdca26" + ], + [ + 1, + "#f0f921" + ] + ], + "type": "heatmap" + } + ], + "heatmapgl": [ + { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + }, + "colorscale": [ + [ + 0, + "#0d0887" + ], + [ + 0.1111111111111111, + "#46039f" + ], + [ + 0.2222222222222222, + "#7201a8" + ], + [ + 0.3333333333333333, + "#9c179e" + ], + [ + 0.4444444444444444, + "#bd3786" + ], + [ + 0.5555555555555556, + "#d8576b" + ], + [ + 0.6666666666666666, + "#ed7953" + ], + [ + 0.7777777777777778, + "#fb9f3a" + ], + [ + 0.8888888888888888, + "#fdca26" + ], + [ + 1, + "#f0f921" + ] + ], + "type": "heatmapgl" + } + ], + "histogram": [ + { + "marker": { + "pattern": { + "fillmode": "overlay", + "size": 10, + "solidity": 0.2 + } + }, + "type": "histogram" + } + ], + "histogram2d": [ + { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + }, + "colorscale": [ + [ + 0, + "#0d0887" + ], + [ + 0.1111111111111111, + "#46039f" + ], + [ + 0.2222222222222222, + "#7201a8" + ], + [ + 0.3333333333333333, + "#9c179e" + ], + [ + 0.4444444444444444, + "#bd3786" + ], + [ + 0.5555555555555556, + "#d8576b" + ], + [ + 0.6666666666666666, + "#ed7953" + ], + [ + 0.7777777777777778, + "#fb9f3a" + ], + [ + 0.8888888888888888, + "#fdca26" + ], + [ + 1, + "#f0f921" + ] + ], + "type": "histogram2d" + } + ], + "histogram2dcontour": [ + { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + }, + "colorscale": [ + [ + 0, + "#0d0887" + ], + [ + 0.1111111111111111, + "#46039f" + ], + [ + 0.2222222222222222, + "#7201a8" + ], + [ + 0.3333333333333333, + "#9c179e" + ], + [ + 0.4444444444444444, + "#bd3786" + ], + [ + 0.5555555555555556, + "#d8576b" + ], + [ + 0.6666666666666666, + "#ed7953" + ], + [ + 0.7777777777777778, + "#fb9f3a" + ], + [ + 0.8888888888888888, + "#fdca26" + ], + [ + 1, + "#f0f921" + ] + ], + "type": "histogram2dcontour" + } + ], + "mesh3d": [ + { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + }, + "type": "mesh3d" + } + ], + "parcoords": [ + { + "line": { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + } + }, + "type": "parcoords" + } + ], + "pie": [ + { + "automargin": true, + "type": "pie" + } + ], + "scatter": [ + { + "fillpattern": { + "fillmode": "overlay", + "size": 10, + "solidity": 0.2 + }, + "type": "scatter" + } + ], + "scatter3d": [ + { + "line": { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + } + }, + "marker": { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + } + }, + "type": "scatter3d" + } + ], + "scattercarpet": [ + { + "marker": { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + } + }, + "type": "scattercarpet" + } + ], + "scattergeo": [ + { + "marker": { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + } + }, + "type": "scattergeo" + } + ], + "scattergl": [ + { + "marker": { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + } + }, + "type": "scattergl" + } + ], + "scattermapbox": [ + { + "marker": { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + } + }, + "type": "scattermapbox" + } + ], + "scatterpolar": [ + { + "marker": { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + } + }, + "type": "scatterpolar" + } + ], + "scatterpolargl": [ + { + "marker": { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + } + }, + "type": "scatterpolargl" + } + ], + "scatterternary": [ + { + "marker": { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + } + }, + "type": "scatterternary" + } + ], + "surface": [ + { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + }, + "colorscale": [ + [ + 0, + "#0d0887" + ], + [ + 0.1111111111111111, + "#46039f" + ], + [ + 0.2222222222222222, + "#7201a8" + ], + [ + 0.3333333333333333, + "#9c179e" + ], + [ + 0.4444444444444444, + "#bd3786" + ], + [ + 0.5555555555555556, + "#d8576b" + ], + [ + 0.6666666666666666, + "#ed7953" + ], + [ + 0.7777777777777778, + "#fb9f3a" + ], + [ + 0.8888888888888888, + "#fdca26" + ], + [ + 1, + "#f0f921" + ] + ], + "type": "surface" + } + ], + "table": [ + { + "cells": { + "fill": { + "color": "#EBF0F8" + }, + "line": { + "color": "white" + } + }, + "header": { + "fill": { + "color": "#C8D4E3" + }, + "line": { + "color": "white" + } + }, + "type": "table" + } + ] + }, + "layout": { + "annotationdefaults": { + "arrowcolor": "#2a3f5f", + "arrowhead": 0, + "arrowwidth": 1 + }, + "autotypenumbers": "strict", + "coloraxis": { + "colorbar": { + "outlinewidth": 0, + "ticks": "" + } + }, + "colorscale": { + "diverging": [ + [ + 0, + "#8e0152" + ], + [ + 0.1, + "#c51b7d" + ], + [ + 0.2, + "#de77ae" + ], + [ + 0.3, + "#f1b6da" + ], + [ + 0.4, + "#fde0ef" + ], + [ + 0.5, + "#f7f7f7" + ], + [ + 0.6, + "#e6f5d0" + ], + [ + 0.7, + "#b8e186" + ], + [ + 0.8, + "#7fbc41" + ], + [ + 0.9, + "#4d9221" + ], + [ + 1, + "#276419" + ] + ], + "sequential": [ + [ + 0, + "#0d0887" + ], + [ + 0.1111111111111111, + "#46039f" + ], + [ + 0.2222222222222222, + "#7201a8" + ], + [ + 0.3333333333333333, + "#9c179e" + ], + [ + 0.4444444444444444, + "#bd3786" + ], + [ + 0.5555555555555556, + "#d8576b" + ], + [ + 0.6666666666666666, + "#ed7953" + ], + [ + 0.7777777777777778, + "#fb9f3a" + ], + [ + 0.8888888888888888, + "#fdca26" + ], + [ + 1, + "#f0f921" + ] + ], + "sequentialminus": [ + [ + 0, + "#0d0887" + ], + [ + 0.1111111111111111, + "#46039f" + ], + [ + 0.2222222222222222, + "#7201a8" + ], + [ + 0.3333333333333333, + "#9c179e" + ], + [ + 0.4444444444444444, + "#bd3786" + ], + [ + 0.5555555555555556, + "#d8576b" + ], + [ + 0.6666666666666666, + "#ed7953" + ], + [ + 0.7777777777777778, + "#fb9f3a" + ], + [ + 0.8888888888888888, + "#fdca26" + ], + [ + 1, + "#f0f921" + ] + ] + }, + "colorway": [ + "#636efa", + "#EF553B", + "#00cc96", + "#ab63fa", + "#FFA15A", + "#19d3f3", + "#FF6692", + "#B6E880", + "#FF97FF", + "#FECB52" + ], + "font": { + "color": "#2a3f5f" + }, + "geo": { + "bgcolor": "white", + "lakecolor": "white", + "landcolor": "#E5ECF6", + "showlakes": true, + "showland": true, + "subunitcolor": "white" + }, + "hoverlabel": { + "align": "left" + }, + "hovermode": "closest", + "mapbox": { + "style": "light" + }, + "paper_bgcolor": "white", + "plot_bgcolor": "#E5ECF6", + "polar": { + "angularaxis": { + "gridcolor": "white", + "linecolor": "white", + "ticks": "" + }, + "bgcolor": "#E5ECF6", + "radialaxis": { + "gridcolor": "white", + "linecolor": "white", + "ticks": "" + } + }, + "scene": { + "xaxis": { + "backgroundcolor": "#E5ECF6", + "gridcolor": "white", + "gridwidth": 2, + "linecolor": "white", + "showbackground": true, + "ticks": "", + "zerolinecolor": "white" + }, + "yaxis": { + "backgroundcolor": "#E5ECF6", + "gridcolor": "white", + "gridwidth": 2, + "linecolor": "white", + "showbackground": true, + "ticks": "", + "zerolinecolor": "white" + }, + "zaxis": { + "backgroundcolor": "#E5ECF6", + "gridcolor": "white", + "gridwidth": 2, + "linecolor": "white", + "showbackground": true, + "ticks": "", + "zerolinecolor": "white" + } + }, + "shapedefaults": { + "line": { + "color": "#2a3f5f" + } + }, + "ternary": { + "aaxis": { + "gridcolor": "white", + "linecolor": "white", + "ticks": "" + }, + "baxis": { + "gridcolor": "white", + "linecolor": "white", + "ticks": "" + }, + "bgcolor": "#E5ECF6", + "caxis": { + "gridcolor": "white", + "linecolor": "white", + "ticks": "" + } + }, + "title": { + "x": 0.05 + }, + "xaxis": { + "automargin": true, + "gridcolor": "white", + "linecolor": "white", + "ticks": "", + "title": { + "standoff": 15 + }, + "zerolinecolor": "white", + "zerolinewidth": 2 + }, + "yaxis": { + "automargin": true, + "gridcolor": "white", + "linecolor": "white", + "ticks": "", + "title": { + "standoff": 15 + }, + "zerolinecolor": "white", + "zerolinewidth": 2 + } + } + }, + "title": { + "text": "Weighted Average Predicted CO2 Rating by Make" + }, + "xaxis": { + "anchor": "y", + "categoryarray": [ + "rivian", + "smart eq", + "lucid", + "polestar", + "karma", + "tesla", + "smart", + "fiat", + "honda", + "mini" + ], + "categoryorder": "array", + "domain": [ + 0, + 1 + ], + "title": { + "text": "make_" + } + }, + "yaxis": { + "anchor": "x", + "domain": [ + 0, + 1 + ], + "title": { + "text": "weighted_avg_predicted_co2_rating_by_make" + } + } + } + } + }, "metadata": {}, - "output_type": "execute_result" + "output_type": "display_data" } ], "source": [ - "weighted_avg_df = pd.merge(total_models_df, make_total_avg_score, on='make_', how='left')\n", - "\n", - "# sort the dataframe by the weighted average\n", - "weighted_avg_df.sort_values(by='weighted_avg_predicted_co2_rating_by_make', ascending=False, inplace=True)\n", - "\n", - "# Display the dataframe\n", - "weighted_avg_df" + "px.bar(df, x='make_', y='weighted_avg_predicted_co2_rating_by_make', \n", + " color='make_', title='Weighted Average Predicted CO2 Rating by Make', \n", + " text='weighted_avg_predicted_co2_rating_by_make', color_discrete_sequence=px.colors.qualitative.Pastel1)" ] }, { diff --git a/src/visualization/dashboard.py b/src/visualization/dashboard.py index fe99add..884ec3f 100644 --- a/src/visualization/dashboard.py +++ b/src/visualization/dashboard.py @@ -67,7 +67,7 @@ def display_top_vehicle_scores(dataframe, view='top'): ]) fig.update_layout( - title=f"{title_str}
Score is taken by computing the average CO2 score of all models in a make, weighted by the total number of models the make has", + title=f"{title_str}Score is taken by computing the average CO2 score of all models in a make, weighted by the total number of models the make has", font=dict( color="white" ),