In [1]:
import pandas as pd
import statsmodels.formula.api as smf
import matplotlib.pyplot as plt
%matplotlib inline
In [41]:
df = pd.read_csv("approval-iran.csv")
In [42]:
df
Out[42]:
In [11]:
#df2 = df.set_index('Group')
In [49]:
lm = smf.ols(formula='Favor_Iran~Approve_Obama',data=df).fit()
lm.params
Out[49]:
In [58]:
intercept, slope = lm.params
In [65]:
plt.style.use('ggplot')
In [87]:
fig, ax = plt.subplots(figsize=(8,5))
df.plot(kind='scatter', x= 'Approve_Obama', y='Favor_Iran',ax=ax,s=50)
plt.plot(df["Approve_Obama"],slope*df["Approve_Obama"]+intercept,"-",color="red",linewidth=2)
ax.set_title("Feelings On Obama Predict Feelings On Iran Deal")
ax.set_ylabel('Favor Iran deal')
ax.set_xlabel("Approve of Obama")
Out[87]:
In [88]:
df.corr()
Out[88]:
In [ ]: