In [36]:
import pandas as pd
%matplotlib inline
import statsmodels.formula.api as smf
import matplotlib.pyplot as plt
In [213]:
df = pd.read_excel("Iran_data_3.xlsx")
In [214]:
df
Out[214]:
In [215]:
df_obama_approve = df[df['Sentiment'] == 'Approve']
In [216]:
df_obama_approve
Out[216]:
In [217]:
del df_obama_approve['Sentiment']
In [218]:
df_favor_iran_deal = df[df['Sentiment'] == 'Favor']
In [219]:
df_favor_iran_deal
Out[219]:
In [220]:
del df_favor_iran_deal['Sentiment']
In [221]:
df_favor_iran_deal
Out[221]:
In [222]:
obama_approve_favor_deal = df_obama_approve.append(df_favor_iran_deal)
In [223]:
obama_approve_favor_deal
Out[223]:
In [224]:
del obama_approve_favor_deal['Subject']
In [225]:
del obama_approve_favor_deal['Total']
In [226]:
obama_approve_favor_deal_transpose = obama_approve_favor_deal.transpose()
In [227]:
obama_approve_favor_deal_transpose.columns = ["Approve_Obama","Favor_Deal"]
obama_approve_favor_deal_transpose
Out[227]:
In [228]:
plt.style.use('fivethirtyeight')
In [229]:
obama_approve_favor_deal_transpose.plot(kind='scatter', x= 'Approve_Obama', y='Favor_Deal')
Out[229]:
In [230]:
obama_approve_favor_deal_transpose.corr()
Out[230]:
In [231]:
lm = smf.ols(formula='Favor_Deal~Approve_Obama',data=obama_approve_favor_deal_transpose).fit()
lm.params
Out[231]:
In [233]:
intercept, slope = lm.params
ax = obama_approve_favor_deal_transpose.plot(kind='scatter', x= 'Approve_Obama', y='Favor_Deal')
plt.plot(obama_approve_favor_deal_transpose["Approve_Obama"],slope*obama_approve_favor_deal_transpose["Approve_Obama"]+intercept,"-",color="red")
ax.set_title("Feelings on Obama predict feelings on Iran deal")
ax.set_ylabel('Favor Iran deal')
ax.set_xlabel("Approve of Obama")
Out[233]:
In [ ]: