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]:
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')
Out[44]:
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')
Out[42]: