-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathcollege_religion.py
49 lines (31 loc) · 1.08 KB
/
college_religion.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
from __future__ import print_function, division
import pandas as pd
import numpy as np
import thinkstats2
import thinkplot
import utils
import matplotlib.pyplot as plt
import seaborn as sns
def run(df):
sample = utils.ResampleByYear(df)
utils.fill_missing(sample, 'educ')
sample['college'] = sample.educ >= 13
utils.fill_missing(sample, 'relig')
sample['none'] = sample.relig ==4
grouped = sample.groupby(['year', 'college'])
percent_none = grouped.none.mean().unstack()
diff = percent_none[True] - percent_none[False]
return diff
def main():
gss = utils.ReadGss('gss_college_religion')
diffs = [run(gss) for _ in range(101)]
years = diffs[0].index
rows = thinkstats2.PercentileRows(diffs, [5, 50, 95])
thinkplot.fill_between(years, rows[0], rows[2], alpha=0.2)
thinkplot.plot(years, rows[1])
thinkplot.config(xlabel='Year',
ylabel='Difference in fraction with no affiliation',
xlim=[1970, 2018])
thinkplot.save(root='college_religion')
if __name__ == '__main__':
main()