Use clean_08.csv
and clean_18.csv
. You should've created these data files in the previous section: Fixing Data Types Pt 3.
# load datasets
import pandas as pd
import matplotlib.pyplot as plt
%matplotlib inline
df_08 = pd.read_csv('clean_08.csv')
df_18 = pd.read_csv('clean_18.csv')
len(df_08[df_08['greenhouse_gas_score'] == 9])
10
df_08.greenhouse_gas_score.hist()
<matplotlib.axes._subplots.AxesSubplot at 0x7f4a62fcdf28>
df_18.greenhouse_gas_score.hist()
<matplotlib.axes._subplots.AxesSubplot at 0x7f4a8c0d4860>
df_08[["city_mpg", "hwy_mpg", "cmb_mpg"]].hist(figsize=(8,8))
array([[<matplotlib.axes._subplots.AxesSubplot object at 0x7f4a8c149d68>, <matplotlib.axes._subplots.AxesSubplot object at 0x7f4a60e6a710>], [<matplotlib.axes._subplots.AxesSubplot object at 0x7f4a60e22710>, <matplotlib.axes._subplots.AxesSubplot object at 0x7f4a60dda630>]], dtype=object)
df_18[["city_mpg", "hwy_mpg", "cmb_mpg"]].hist(figsize=(8,8))
array([[<matplotlib.axes._subplots.AxesSubplot object at 0x7f4a60b85828>, <matplotlib.axes._subplots.AxesSubplot object at 0x7f4a60bbe2e8>], [<matplotlib.axes._subplots.AxesSubplot object at 0x7f4a60d3c358>, <matplotlib.axes._subplots.AxesSubplot object at 0x7f4a60cf5358>]], dtype=object)
Negative Correlation - below code supports my conclusion
df_08.groupby(['cmb_mpg', 'displ']).mean()
cyl | air_pollution_score | city_mpg | hwy_mpg | greenhouse_gas_score | ||
---|---|---|---|---|---|---|
cmb_mpg | displ | |||||
10.0 | 6.5 | 12.000000 | 6.000000 | 8.000000 | 13.000000 | 0.000000 |
8.0 | 16.000000 | 6.000000 | 8.000000 | 14.000000 | 0.000000 | |
11.0 | 5.7 | 12.000000 | 6.000000 | 9.000000 | 16.000000 | 0.000000 |
6.5 | 12.000000 | 6.000000 | 9.000000 | 14.000000 | 0.000000 | |
6.7 | 8.000000 | 6.000000 | 9.333333 | 15.000000 | 0.000000 | |
12.0 | 5.0 | 10.000000 | 6.000000 | 10.000000 | 15.500000 | 0.000000 |
5.4 | 8.000000 | 6.000000 | 11.000000 | 13.000000 | 0.000000 | |
5.5 | 12.000000 | 6.000000 | 10.000000 | 16.000000 | 0.000000 | |
5.7 | 12.000000 | 6.000000 | 10.000000 | 15.000000 | 0.000000 | |
5.9 | 12.000000 | 6.000000 | 10.500000 | 15.500000 | 0.000000 | |
6.0 | 12.000000 | 6.000000 | 10.000000 | 16.500000 | 0.000000 | |
6.1 | 8.000000 | 6.000000 | 11.000000 | 14.000000 | 0.000000 | |
13.0 | 5.0 | 9.333333 | 6.000000 | 11.000000 | 16.333333 | 1.000000 |
5.4 | 8.000000 | 6.666667 | 11.333333 | 15.333333 | 1.000000 | |
5.5 | 12.000000 | 6.000000 | 11.000000 | 17.000000 | 1.000000 | |
5.9 | 12.000000 | 6.000000 | 11.000000 | 17.500000 | 1.000000 | |
6.0 | 10.000000 | 6.000000 | 11.250000 | 16.500000 | 1.000000 | |
6.2 | 8.000000 | 6.000000 | 11.000000 | 17.000000 | 1.000000 | |
14.0 | 4.2 | 8.000000 | 6.000000 | 12.000000 | 17.800000 | 2.000000 |
4.4 | 8.000000 | 6.500000 | 12.000000 | 17.500000 | 2.000000 | |
4.5 | 8.000000 | 6.000000 | 13.000000 | 17.000000 | 2.000000 | |
4.6 | 8.000000 | 6.000000 | 13.000000 | 17.000000 | 2.000000 | |
4.7 | 8.000000 | 6.250000 | 12.750000 | 16.750000 | 2.000000 | |
4.8 | 8.000000 | 6.000000 | 12.000000 | 19.000000 | 2.000000 | |
5.0 | 9.714286 | 6.000000 | 12.000000 | 18.142857 | 2.000000 | |
5.3 | 8.000000 | 6.000000 | 12.000000 | 16.000000 | 2.000000 | |
5.4 | 8.000000 | 6.857143 | 12.428571 | 17.142857 | 2.000000 | |
5.5 | 10.000000 | 6.500000 | 12.000000 | 17.500000 | 2.000000 | |
5.6 | 8.000000 | 6.000000 | 12.000000 | 17.428571 | 2.000000 | |
5.7 | 8.000000 | 6.500000 | 12.750000 | 17.250000 | 2.000000 | |
... | ... | ... | ... | ... | ... | ... |
25.0 | 2.4 | 4.000000 | 6.777778 | 21.722222 | 30.500000 | 7.000000 |
3.0 | 6.000000 | 7.666667 | 23.000000 | 31.000000 | 7.000000 | |
3.3 | 6.000000 | 9.000000 | 26.500000 | 24.000000 | 7.000000 | |
26.0 | 1.6 | 4.000000 | 6.000000 | 22.000000 | 31.000000 | 8.000000 |
2.0 | 4.000000 | 7.250000 | 23.000000 | 30.750000 | 8.000000 | |
2.2 | 4.000000 | 7.500000 | 22.000000 | 31.000000 | 8.000000 | |
2.4 | 4.000000 | 6.000000 | 22.000000 | 32.000000 | 8.000000 | |
2.5 | 4.000000 | 7.333333 | 23.111111 | 31.333333 | 8.000000 | |
3.3 | 6.000000 | 9.000000 | 27.000000 | 25.000000 | 8.000000 | |
27.0 | 1.6 | 4.000000 | 6.000000 | 24.000000 | 31.000000 | 8.000000 |
1.8 | 4.000000 | 7.000000 | 24.666667 | 31.333333 | 8.000000 | |
2.0 | 4.000000 | 7.800000 | 24.000000 | 32.000000 | 8.000000 | |
2.2 | 4.000000 | 7.500000 | 24.000000 | 33.000000 | 8.000000 | |
2.4 | 4.000000 | 6.000000 | 24.000000 | 32.000000 | 8.000000 | |
28.0 | 1.6 | 4.000000 | 6.500000 | 24.500000 | 33.000000 | 8.000000 |
1.8 | 4.000000 | 7.333333 | 25.333333 | 33.000000 | 8.333333 | |
2.0 | 4.000000 | 8.200000 | 24.600000 | 33.400000 | 8.000000 | |
2.3 | 4.000000 | 9.000000 | 29.000000 | 27.000000 | 8.000000 | |
29.0 | 1.5 | 4.000000 | 6.000000 | 27.000000 | 33.000000 | 8.000000 |
1.6 | 4.000000 | 6.750000 | 26.250000 | 33.500000 | 8.000000 | |
1.8 | 4.000000 | 6.857143 | 26.142857 | 33.857143 | 8.000000 | |
30.0 | 1.5 | 4.000000 | 6.000000 | 27.000000 | 34.000000 | 8.000000 |
31.0 | 1.5 | 4.000000 | 6.500000 | 28.500000 | 34.500000 | 9.000000 |
1.8 | 4.000000 | 7.000000 | 28.000000 | 37.000000 | 9.000000 | |
32.0 | 1.5 | 4.000000 | 7.000000 | 29.000000 | 36.000000 | 9.000000 |
2.3 | 4.000000 | 9.000000 | 34.000000 | 30.000000 | 9.000000 | |
34.0 | 2.4 | 4.000000 | 9.000000 | 33.000000 | 34.000000 | 9.000000 |
2.5 | 4.000000 | 9.000000 | 35.000000 | 33.000000 | 9.000000 | |
42.0 | 1.3 | 4.000000 | 9.000000 | 40.000000 | 45.000000 | 10.000000 |
46.0 | 1.5 | 4.000000 | 9.000000 | 48.000000 | 45.000000 | 10.000000 |
212 rows × 5 columns
Positive Correlation - below code concludes my answer
df_08.groupby(['cmb_mpg', 'greenhouse_gas_score']).mean()
displ | cyl | air_pollution_score | city_mpg | hwy_mpg | ||
---|---|---|---|---|---|---|
cmb_mpg | greenhouse_gas_score | |||||
10.0 | 0 | 7.000000 | 13.333333 | 6.000000 | 8.000000 | 13.333333 |
11.0 | 0 | 6.471429 | 10.285714 | 6.000000 | 9.142857 | 14.714286 |
12.0 | 0 | 5.720000 | 11.200000 | 6.000000 | 10.266667 | 15.533333 |
13.0 | 1 | 5.606250 | 10.000000 | 6.125000 | 11.125000 | 16.500000 |
14.0 | 2 | 5.346875 | 8.312500 | 6.171875 | 12.140625 | 17.406250 |
15.0 | 3 | 4.936585 | 7.829268 | 6.378049 | 13.292683 | 18.414634 |
7 | 3.000000 | 6.000000 | 6.000000 | 13.000000 | 19.000000 | |
16.0 | 4 | 4.452830 | 7.094340 | 6.415094 | 13.943396 | 19.754717 |
17.0 | 4 | 3.972131 | 6.360656 | 6.475410 | 14.983607 | 20.327869 |
18.0 | 5 | 3.755844 | 6.311688 | 6.402597 | 15.571429 | 22.311688 |
19.0 | 5 | 3.457303 | 6.022472 | 6.561798 | 16.438202 | 23.730337 |
20.0 | 6 | 3.354255 | 5.893617 | 6.510638 | 17.351064 | 24.542553 |
21.0 | 6 | 2.839286 | 5.142857 | 6.535714 | 18.464286 | 25.369048 |
22.0 | 6 | 2.725743 | 4.900990 | 6.831683 | 19.356436 | 26.821782 |
23.0 | 7 | 2.489831 | 4.762712 | 7.186441 | 20.135593 | 27.576271 |
24.0 | 7 | 2.401493 | 4.507463 | 7.313433 | 21.089552 | 29.000000 |
25.0 | 7 | 2.458333 | 4.444444 | 7.055556 | 22.250000 | 29.972222 |
26.0 | 8 | 2.325000 | 4.083333 | 7.208333 | 22.791667 | 30.958333 |
27.0 | 8 | 2.058824 | 4.000000 | 7.235294 | 24.117647 | 32.176471 |
28.0 | 8 | 1.975000 | 4.000000 | 7.833333 | 25.916667 | 31.416667 |
9 | 1.800000 | 4.000000 | 9.000000 | 24.000000 | 36.000000 | |
29.0 | 8 | 1.708333 | 4.000000 | 6.750000 | 26.250000 | 33.666667 |
30.0 | 8 | 1.500000 | 4.000000 | 6.000000 | 27.000000 | 34.000000 |
31.0 | 9 | 1.600000 | 4.000000 | 6.666667 | 28.333333 | 35.333333 |
32.0 | 9 | 2.100000 | 4.000000 | 8.500000 | 32.750000 | 31.500000 |
34.0 | 9 | 2.450000 | 4.000000 | 9.000000 | 34.000000 | 33.500000 |
42.0 | 10 | 1.300000 | 4.000000 | 9.000000 | 40.000000 | 45.000000 |
46.0 | 10 | 1.500000 | 4.000000 | 9.000000 | 48.000000 | 45.000000 |