<jupyter_start><jupyter_text>NOMINATE scoresThis analysis uses the [NOMINATE](https://en.wikipedia.org/wiki/NOMINATE_(scaling_method)) scores from: https://voteview.com/data<jupyter_code>moc_df = pd.read_csv('Hall_members.csv')
moc_df.head()
mk_df = moc_df[moc_df['bioname'] == '<NAME>']
mk_df
mk_dim1 = mk_df['nominate_dim1'].mean()
mk_dim2 = mk_df['nominate_dim2'].mean()

print(mk_dim1,mk_dim2)<jupyter_output>0.409 0.304<jupyter_text>Compared to all Colorado legislators since the 80th Congress (1947–2019)<jupyter_code>postwar_co_df = moc_df[(moc_df['state_abbrev'] == 'CO') & (moc_df['congress'] >= 80)]

f,axs = plt.subplots(1,2,figsize=(12,6),sharex=True,subplot_kw={'ylim':(0,40),'xlim':(-1,1)})
postwar_co_df[['nominate_dim1','nominate_dim2']].hist(bins=25,ax=axs,color='k',alpha=.5)
axs[0].axvline(mk_dim1,c='r',lw=3)
axs[1].axvline(mk_dim2,c='r',lw=3)

axs[0].set_ylabel('NOMINATE, Dimension 1')
axs[1].set_ylabel('NOMINATE, Dimension 2')

for _ax in axs:
    _ax.axvline(0,c='k',lw=1,ls='--')
    _ax.grid(None)
    _ax.set_title(None)

axs[0].text(s="Kennedy: {:.3f}".format(mk_dim1),x=mk_dim1+.025,y=37.5,color='r',horizontalalignment='left')
axs[1].text(s="Kennedy: {:.3f}".format(mk_dim2),x=mk_dim2+.025,y=37.5,color='r',horizontalalignment='left')

f.suptitle('All Colorado Representatives, 1947–2019',fontsize=16)
f.tight_layout(rect=[0, 0.03, 1, 0.95])
f.savefig('nominate_all_co.png',dpi=300)<jupyter_output><empty_output><jupyter_text>These scores are more extreme than what percentage of the population?<jupyter_code>1 - (postwar_co_df['nominate_dim1'] > mk_df['nominate_dim1'].mean()).sum()/len(postwar_co_df)
1 - (postwar_co_df['nominate_dim2'] > mk_df['nominate_dim2'].mean()).sum()/len(postwar_co_df)<jupyter_output><empty_output><jupyter_text>Compared to all legislators in 107th, 108th, and 109th Congresses<jupyter_code>postmillenium_df = moc_df[(moc_df['congress'] > 106) & (moc_df['congress'] < 110)].copy()

f,axs = plt.subplots(1,2,figsize=(12,6),sharex=True,
                     subplot_kw={'ylim':(0,180),'xlim':(-1,1)})
postmillenium_df[['nominate_dim1','nominate_dim2']].hist(bins=25,ax=axs,color='k',alpha=.5)
axs[0].axvline(mk_dim1,c='r',lw=3)
axs[1].axvline(mk_dim2,c='r',lw=3)

for _ax in axs:
    _ax.axvline(0,c='k',lw=1,ls='--')
    _ax.grid(None)
    _ax.set_title(None)

axs[0].text(s="Kennedy: {:.3f}".format(mk_dim1),x=mk_dim1+.025,y=170,color='r',horizontalalignment='left')
axs[1].text(s="Kennedy: {:.3f}".format(mk_dim2),x=mk_dim2+.025,y=170,color='r',horizontalalignment='left')

axs[0].set_ylabel('NOMINATE, Dimension 1')
axs[1].set_ylabel('NOMINATE, Dimension 2')

f.suptitle('All House Representatives, 107th–109th Congresses',fontsize=16)

f.tight_layout(rect=[0, 0.03, 1, 0.95])
f.savefig('nominate_all_107-109.png',dpi=300)<jupyter_output><empty_output><jupyter_text>These scores are more extreme than what percentage of the population?<jupyter_code>1 - (postmillenium_df['nominate_dim1'] > mk_df['nominate_dim1'].mean()).sum()/len(postmillenium_df)
1 - (postmillenium_df['nominate_dim2'] > mk_df['nominate_dim2'].mean()).sum()/len(postmillenium_df)<jupyter_output><empty_output><jupyter_text>2D plot with most-similar opposing member<jupyter_code>postmillenium_df = postmillenium_df[['nominate_dim1','nominate_dim2']].apply(lambda x:euclidean(x,[mk_dim1,mk_dim2]),axis=1)
c1 = -.45 < postmillenium_df['nominate_dim1']
c2 = postmillenium_df['nominate_dim1'] < -.35
c3 = -.35 < postmillenium_df['nominate_dim2']
c4 = postmillenium_df['nominate_dim2'] < -.25
dem_nominate_df = postmillenium_df[c1 & c2 & c3 & c4].drop_duplicates(subset='icpsr').copy()

dem_nominate_df['distance'] = dem_nominate_df[['nominate_dim1','nominate_dim2']].apply(lambda x:euclidean(x,[-mk_dim1,-mk_dim2]),axis=1)
dem_nominate_df.sort_values('distance',ascending=True)
f,ax = plt.subplots(1,1,figsize=(8,6),sharex=True,subplot_kw={'ylim':(-1.5,1.5),'xlim':(-1,1)})
postmillenium_df[postmillenium_df['party_code']==100].plot.scatter(x='nominate_dim1',y='nominate_dim2',c='b',s=15,ax=ax)
postmillenium_df[postmillenium_df['party_code']==200].plot.scatter(x='nominate_dim1',y='nominate_dim2',c='r',s=15,ax=ax)

ax.scatter(mk_dim1,mk_dim2,s=350,marker='^',lw=3,c='w',zorder=1,edgecolor='k')
ax.scatter(-mk_dim1,-mk_dim2,s=350,marker='v',lw=3,c='w',zorder=1,edgecolor='k')
ax.annotate(s='Kennedy',xy=(mk_dim1,mk_dim1-.1),xytext=(mk_dim1+.25,mk_dim1+.25),
            arrowprops=dict(facecolor='black', shrink=0.05),horizontalalignment='left', verticalalignment='top')
ax.annotate(s='Doggett',xy=(-mk_dim1,-mk_dim1+.05),xytext=(-mk_dim1-.25,-mk_dim1-.35),
            arrowprops=dict(facecolor='black', shrink=0.05),horizontalalignment='left', verticalalignment='top')
ax.axvline(0,ls='--',lw=1,c='k')
ax.axhline(0,ls='--',lw=1,c='k')
f.tight_layout()
f.savefig('nominate_kennedy_doggett.png',dpi=300)<jupyter_output><empty_output><jupyter_text>Presidential supportThis analysis uses presidential support scores from: https://voteview.com/articles/presidential_support_scores<jupyter_code>pres_df = pd.read_csv('house_presidential_support.csv')
pres_df.head()
mark_pres_df = pres_df[pres_df['icpsr'] == 20121]

f,axs = plt.subplots(1,3,figsize=(12,4),sharey=True,subplot_kw={'ylim':(0,120),'xlim':(0,100)})

pres_df.loc[pres_df['congress'] == 107,'score'].hist(bins=25,ax=axs[0],color='k',alpha=.5)
pres_df.loc[pres_df['congress'] == 108,'score'].hist(bins=25,ax=axs[1],color='k',alpha=.5)
pres_df.loc[pres_df['congress'] == 109,'score'].hist(bins=25,ax=axs[2],color='k',alpha=.5)

for i,_ax in enumerate(axs):
    _ax.grid(None)
    _ax.set_title('{0}th Congress'.format(107+i))
    _ax.set_xlabel('Presidential support score')

axs[0].set_ylabel('Number of Representatives')

mark_107_pres_score = mark_pres_df.loc[mark_pres_df['congress'] == 107,'score'].mean()
mark_108_pres_score = mark_pres_df.loc[mark_pres_df['congress'] == 108,'score'].mean()
mark_109_pres_score = mark_pres_df.loc[mark_pres_df['congress'] == 109,'score'].mean()

axs[0].axvline(mark_107_pres_score,c='r',lw=3)
axs[1].axvline(mark_108_pres_score,c='r',lw=3)
axs[2].axvline(mark_109_pres_score,c='r',lw=3)

axs[0].axvline(50,c='k',lw=1,ls='--')
axs[1].axvline(50,c='k',lw=1,ls='--')
axs[2].axvline(50,c='k',lw=1,ls='--')

axs[0].text(s="Kennedy: {:.1f}%".format(mark_107_pres_score),x=mark_107_pres_score-1.5,y=110,color='r',horizontalalignment='right')
axs[1].text(s="Kennedy: {:.1f}%".format(mark_108_pres_score),x=mark_108_pres_score-1.5,y=110,color='r',horizontalalignment='right')
axs[2].text(s="Kennedy: {:.1f}%".format(mark_109_pres_score),x=mark_109_pres_score-1.5,y=110,color='r',horizontalalignment='right')

f.tight_layout()
f.savefig('presidential_support.png',dpi=300)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.2123920166815609, 'fraction_numerical': 0.06344950848972297, 'mean_word_length': 10.117549668874172, 'pattern_counts': {'":': 0, '<': 34, '<?xml version=': 0, '>': 35, 'https://': 3, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '116817', 'license': 'MIT', 'n_tokens_mistral': 3202, 'n_tokens_neox': 2927, 'n_words': 244, 'path': 'Congress/NOMINATE.ipynb', 'repo_name': 'brianckeegan/markkennedy', 'size': '6721'}