In [1]:
import pandas as pd
import numpy as np
%matplotlib inline
import plotly.plotly as py
import plotly.graph_objs as go
from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot
init_notebook_mode(connected=True)
In [2]:
df = pd.read_stata('~/../../statadata/IPEDSDirInfo02to18.dta')
In [8]:
state_counts_2018 = pd.DataFrame(df[df['isYr'] == 2018]['stabbr'].value_counts())
state_counts_2018.rename(columns = {'stabbr':'Total Institutions'}, inplace=True)
scratch = {}
for sec in df['sector'].unique():
scratch[sec] = pd.DataFrame(df[(df['isYr'] == 2018) &
(df['sector'] == sec)]['stabbr'].value_counts())
scratch[sec].rename(columns = {'stabbr':sec}, inplace=True)
state_counts_2018 = pd.merge(state_counts_2018, scratch[sec],
left_index=True,
right_index=True,
how='outer')
state_counts_2018.reset_index(inplace=True)
In [12]:
state_counts_2018.head()
Out[12]:
In [18]:
data = {'type':'choropleth',
'locations':state_counts_2018['index'],
'locationmode':'USA-states',
'colorscale':'Greens',
'reversescale':True,
'z':state_counts_2018['Total Institutions'],
'colorbar':{'title':'Counts'}}
layout = {'geo':{'scope':'usa'}}
choromap = go.Figure(data=[data], layout=layout)
In [20]:
iplot(choromap)
In [ ]: