In [1]:
import pandas as pd
import matplotlib.pyplot as plt
plt.style.use('fivethirtyeight')
%matplotlib inline
import statsmodels.formula.api as smf
df = pd.read_excel('Untitled spreadsheet.xlsx')
In [32]:
df.columns ='Demographic', 'Approve_of_Obama', 'Favor_Iran_Deal'
df.head(3)
Out[32]:
In [33]:
df.corr()['Favor_Iran_Deal'].sort_values(ascending=False)
Out[33]:
In [34]:
lm = smf.ols(formula="Favor_Iran_Deal~Approve_of_Obama",data=df).fit()
lm.params
Out[34]:
In [35]:
intercept, slope = lm.params
In [37]:
df.plot(kind="scatter",x="Approve_of_Obama",y="Favor_Iran_Deal")
plt.plot(df["Approve_of_Obama"],slope*df["Approve_of_Obama"]+intercept,"-",color="darkgrey")
plt.xlabel('Approve of Obama')
plt.ylabel('Favors Iran Deal')
Out[37]: