I wish the data was here! https://github.com/fivethirtyeight/data


In [1]:
import pandas as pd
import matplotlib.pyplot as plt
%matplotlib inline
import statsmodels.formula.api as smf

In [4]:
df = pd.read_excel('ronga_fox.xls')
df.shape


Out[4]:
(19, 11)

In [44]:
print("Correlation between % of 'Approve Obama' and % of 'Favor Iran Deal':", df.corr()['Approve Barack Obama']['Favor Iran Deal'])
plt.scatter(df['Approve Barack Obama'], df['Favor Iran Deal'], c='black', alpha='.5')


Correlation between % of 'Approve Obama' and % of 'Favor Iran Deal': 0.91353620056
Out[44]:
<matplotlib.collections.PathCollection at 0x1103c4438>

In [42]:
print("Correlation between % of 'Approve Obama' and % of 'Very confident in the administration…':", df.corr()['Approve Barack Obama']['Very confident'])
plt.scatter(df['Approve Barack Obama'], df['Very confident'], c='black', alpha='.5')


Correlation between % of 'Approve Obama' and % of 'Very confident in the administration…': 0.968018704594
Out[42]:
<matplotlib.collections.PathCollection at 0x10ffcc550>