In [20]:
#Contribute to Yuxiang Ling#
import plotly 
plotly.tools.set_credentials_file(username='huilyu2', api_key='LYEkqxDQFmZzZIBXn9rn')
import plotly.plotly as py

In [21]:
import pandas as pd

In [22]:
df = pd.read_csv('/Users/yiling10/Downloads/Administrative_Discretionary_Grants_Dataset.csv')

In [23]:
df.head()


Out[23]:
Log Number Institution Program Program Type Project Title Project Type Award Date Address Address 2 Address 3 ... County Code Census Tract Census Block MCD Code Place Code CBSA Code MSAD Code Description Location Organizational Unit Location
0 IM-01-02-0010-02 Fire Museum of Maryland Museum Assessment Program IM NaN Institutional 3/27/02 0:00 1301 York Road NaN NaN ... 5.0 408703.0 2001.0 90656.0 51587.0 12580.0 NaN NaN 1301 York Road\rLutherville, MD 21093\r(39.417... NaN
1 IM-01-03-0032-03 Loxahatchee River Historical Museum Museum Assessment Program IM NaN Institutional 38020 805 North U.S. Highway 1 NaN NaN ... 99.0 408.0 2003.0 91690.0 35875.0 33100.0 48424.0 NaN 805 North U.S. Highway 1\rJupiter, FL 33477\r(... NaN
2 LL-30-99-0194-99 Museum of Science and Industry, Chicago National Leadership Grants (LL) LL NaN NLG LMC 7/12/99 0:00 57th Street and Lake Shore Drive NaN NaN ... 31.0 411000.0 1008.0 14000.0 14000.0 16980.0 16974.0 NaN 57th Street and Lake Shore Drive\rChicago, IL ... NaN
3 IC-22-10-0036-10 County of Delaware Conservation Program IC Collection Storage Improvement AHPG-Library 2/22/10 0:00 44 Burrer Drive NaN NaN ... 41.0 11604.0 2023.0 75620.0 75602.0 18140.0 NaN The County of Delaware Community Library in Su... 44 Burrer Drive\rSunbury, OH 43074-9319\r(40.2... NaN
4 IC-21-11-0142-11 Plimoth Plantation Conservation Program IC Rare Book Rehousing Project AHPG-Museum 37875 P.O. Box 1620 NaN NaN ... 23.0 530600.0 1040.0 54310.0 NaN 14460.0 14454.0 Plimoth Plantation will re-house the museum's ... P.O. Box 1620\rPlymouth, MA 02362-1620\r NaN

5 rows × 39 columns


In [24]:
df['text'] = df['Program'] +'<br>'+ 'Total Amount Awarded and Disbursed:  ' + (df['Total Amount Awarded and Disbursed']/1e3).astype(str)+'thousand'+'<br>'+ 'State: '+ df['State']
limits = [(0,10),(10,100),(100,200),(200,500),(500,1000),(1000,3000)]
colors = ["rgb(92,167,186)","rgb(131,175,155)","rgb(200,200,169)","rgb(249,205,173)","rgb(252,157,154)","rgb(254,67,101)"]
Programs = []
scale = 6000

In [25]:
for i in range(len(limits)):
    lim = limits[i]
    df_sub = df[((df['Total Amount Awarded and Disbursed']/1e3)<limits[i][1])&((df['Total Amount Awarded and Disbursed']/1e3)>limits[i][0])]
    program = dict(
        type = 'scattergeo',
        locationmode = 'USA-states',
        lon = df_sub['LNG'],
        lat = df_sub['LAT'],
        text = df_sub['text'],
        marker = dict(
            size = df_sub['Total Amount Awarded and Disbursed']/scale,
            color = colors[i],
            line = dict(width=0.5, color='rgb(255,255,255)'),
            opacity = 0.7,
            sizemode = 'area'
        ),
        name = '{0} - {1}'.format(limits[i][0],limits[i][1]) )
    Programs.append(program)

layout = dict(
    geo = dict(
        scope = 'north america',
        showland = True,
        landcolor = "rgb(212, 212, 212)",
        subunitcolor = "rgb(255, 255, 255)",
        countrycolor = "rgb(255, 255, 255)",
        showlakes = True,
        lakecolor = "rgb(255, 255, 255)",
        showsubunits = True,
        showcountries = True,
        resolution = 50,
        projection = dict(
            type = 'conic conformal',
            rotation = dict(
                lon = -100
            )
        ),
        lonaxis = dict(
            showgrid = True,
            gridwidth = 0.5,
            range= [ -140.0, -55.0 ],
            dtick = 5
        ),
        lataxis = dict (
            showgrid = True,
            gridwidth = 0.5,
            range= [ 20.0, 60.0 ],
            dtick = 5
        )
    ),
    title = 'Total Amount Awarded and Disbursed<br>(Click legend to toggle traces)')
fig = dict( data=Programs, layout=layout )
py.iplot( fig, validate=False, filename='Total_Amount_Awarded_and_Disbursed' )


Out[25]:

In [ ]:


In [4]:



  File "<ipython-input-4-34013077ebfd>", line 1
    pip install pyzipcode-cli
              ^
SyntaxError: invalid syntax

In [5]:



---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-5-30adcccb8e61> in <module>()
----> 1 from pyzipcode import ZipCodeDatabase

ImportError: cannot import name 'ZipCodeDatabase'

In [6]:



  File "<ipython-input-6-32a55c2d7ffe>", line 1
    pip install -i https://pypi.anaconda.org/pypi/simple pyzipcode
              ^
SyntaxError: invalid syntax

In [7]:



---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-7-30adcccb8e61> in <module>()
----> 1 from pyzipcode import ZipCodeDatabase

ImportError: cannot import name 'ZipCodeDatabase'

In [8]:



---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-8-30adcccb8e61> in <module>()
----> 1 from pyzipcode import ZipCodeDatabase

ImportError: cannot import name 'ZipCodeDatabase'

In [ ]: