Project Code

Obesity Rate Mapping and Statistics

In [97]:
import pandas as pd
import folium

county_geo = "counties.geojson"
county_poverty= "ChiefKeef2.csv"
county_data = pd.read_csv(county_poverty)
#county_data['NAME'] = county_data['NAME'].astype('str')
#county_data['x'] = county_data['x'].astype('int')
m = folium.Map(location=[48, -102], zoom_start=3)
folium.Choropleth(
    geo_data=county_geo,
    name="choropleth",
    data=county_data,
    columns=['NAME', 'x'],
    key_on="feature.properties.NAME",
    fill_color="YlOrRd",
    fill_opacity=0.7,
    line_opacity=0.2,
    legend_name="Obesity Rate",
).add_to(m)
folium.LayerControl().add_to(m)
m
Out[97]:
Make this Notebook Trusted to load map: File -> Trust Notebook

Poverty Rate Mapping and Statistics

In [98]:
import pandas as pd
import folium

county_geo = "counties.geojson"
county_poverty= "ChiefKeef2.csv"
county_data = pd.read_csv(county_poverty)
#county_data['NAME'] = county_data['NAME'].astype('str')
#county_data['x'] = county_data['x'].astype('int')
m = folium.Map(location=[48, -102], zoom_start=3)
folium.Choropleth(
    geo_data=county_geo,
    name="choropleth",
    data=county_data,
    columns=['NAME', 'y'],
    key_on="feature.properties.NAME",
    fill_color="YlOrRd",
    fill_opacity=0.7,
    line_opacity=0.2,
    legend_name="Poverty Rate",
).add_to(m)
folium.LayerControl().add_to(m)
m
Out[98]:
Make this Notebook Trusted to load map: File -> Trust Notebook

Scatter Plot

In [94]:
import matplotlib.pyplot as plt
import csv
%matplotlib inline
import os
from matplotlib import pyplot as plt
import pandas as pd
import seaborn as sb

Data_Points = pd.read_csv("CountyObesityPovertyDolla.csv")
features = Data_Points[["x","y"]]
plt.scatter(features['x'], features['y'])
plt.xlabel('Obesity Percentage')
plt.ylabel('Poverty Percentage')
plt.title('Obesity vs. Poverty by US County')
plt.gcf().set_size_inches((26,26))
Data_Points.corr(method='pearson')
sb.regplot(x = "x", y = "y", ci = None, data = Data_Points)
Out[94]:
<AxesSubplot:title={'center':'Obesity vs. Poverty by US County'}, xlabel='x', ylabel='y'>

Pearson Correlation Coefficient between Obesity and Poverty

In [59]:
import pandas as pd

Data_Points = pd.read_csv("CountyObesityPovertyDolla.csv")
Data_Points.corr(method='pearson')
Out[59]:
x y
x 1.000000 0.284595
y 0.284595 1.000000

Numerical Measures of Obesity and Poverty by County

In [93]:
import pandas as pd

Data_Points = pd.read_csv("CountyObesityPovertyDolla.csv")
Data_Points[["x","y"]].describe()
Out[93]:
x y
count 3142.000000 3142.000000
mean 0.334324 0.159874
std 0.059250 0.065577
min 0.110003 0.024293
25% 0.296368 0.113497
50% 0.337007 0.151912
75% 0.373015 0.193960
max 0.589038 0.519579
In [101]:
import csv
%matplotlib inline
import os
from matplotlib import pyplot as plt
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
import seaborn as sb

Data_Points = pd.read_csv("ObesityPoverty.csv")
features = Data_Points[["X","Y"]]
plt.scatter(features['X'], features['Y'])
plt.xlabel('Obesity Percentage')
plt.ylabel('Poverty Percentage')
plt.title('Obesity vs. Poverty by US State with Linear Regression')
sb.regplot(x = "X", y = "Y", ci = None, data = Data_Points)




#Alternate Regression Code
#b, a = np.polyfit(features['X'], features['Y'], deg=1)
#xseq = np.linspace(25, 40, num=50)
#plt.plot(xseq, a + b * xseq, color="k", lw=2.5);
Out[101]:
<AxesSubplot:title={'center':'Obesity vs. Poverty by US State with Linear Regression'}, xlabel='X', ylabel='Y'>
In [90]:
import pandas as pd

Data_Points2 = pd.read_csv("ObesityPoverty.csv")
Data_Points2.corr(method='pearson')
Out[90]:
X Y
X 1.000000 0.463095
Y 0.463095 1.000000
In [89]:
import pandas as pd
Data_Points = pd.read_csv("ObesityPoverty.csv")
Data_Points[["X","Y"]].describe()
Out[89]:
X Y
count 51.000000 51.000000
mean 33.762745 8.545098
std 4.056795 2.318389
min 24.300000 4.700000
25% 31.000000 6.700000
50% 33.600000 7.700000
75% 37.200000 10.050000
max 41.000000 14.500000
In [ ]:
#.26846 Results of the pearson correlation indicated that there is a significant small positive relationshi between X and Y, (r(3140) = .285, p < .001)