Politicians Module

Instructions / Notes:

Read these carefully

  • Read and execute each cell in order, without skipping forward
  • You may create new Jupyter notebook cells to use for e.g. testing, debugging, exploring, etc.- this is encouraged in fact!- just make sure that your final answer dataframes and answers use the set variables outlined below
  • Have fun!

In [1]:
# Run the following to import necessary packages and import dataset. Do not use any additional plotting libraries.
import pandas as pd

from modules.util_politicians import evaluate, toggle_display

dataset = "dataset/politicians.csv"
df = pd.read_csv(dataset)
df.head()


Out[1]:
Year Dem_Presidents Rep_Presidents Dem_Governors Rep_Governors Employment GDP
0 1 1 0 5 45 10.0 800
1 2 1 0 10 40 9.0 120
2 3 1 0 15 35 9.0 130
3 4 1 0 20 30 28.0 170
4 5 1 0 30 20 7.0 150

Try to find publishable (i.e., statistically significant) results about the U.S. economy and which politicians are in charge


In [5]:
d_politicians, d_economy, d_outliers = toggle_display('Democrats')


Analyzing Party: Democrats

Toggle the variables above and run the evaluate() function until you find a publishable result!


In [10]:
# Part 1 Democrats
d_pval, d_corr = evaluate(df, 'Democrats', d_politicians, d_economy, d_outliers, 1)


Dem_Governors
GDP
Exclude
Correlation 0.868813280324 P-value 5.51446043268e-05
Part 1 : Democrats have a positive impact on the economy!
By achieving a p-value of less than 0.05, your result is publishable!

In [ ]:
r_politicians, r_economy, r_outliers = toggle_display('republican')

Toggle the variables above and run evaluate until you find a publishable result!


In [ ]:
# Part 1 Republicans
r_pval, r_corr = evaluate(df, 'Republicans', r_politicians, r_economy, r_outliers, 1)

Clue

Read this article on P-Hacking: https://fivethirtyeight.com/features/science-isnt-broken/

If you found that both parties impact the economy positively or negatively, try again below to show that one party is better than the other on the economy. If you already found one party is better than the other, try again below to find the opposite relationship.


In [ ]:
d_politicians_clue, d_economy_clue, d_outliers_clue = toggle_display('Democrats')

In [ ]:
# Part 2 Democrats
d_pval_clue, d_corr_clue = evaluate(df, 'Democrats', d_politicians_clue, d_economy_clue, d_outliers_clue, 2)

In [ ]:
r_politicians_clue, r_economy_clue, r_outliers_clue = toggle_display('republican')

In [ ]:
# Part 2 Republicans
r_pval_clue, r_corr_clue = evaluate(df, 'Republicans', r_politicians_clue, r_economy_clue, r_outliers_clue, 2)

In [ ]: