In [1]:
import plotly.plotly as py

In [2]:
import pandas as pd

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

In [4]:
df.head()


Out[4]:
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 [20]:
df['text'] = df['Program'] +'<br>'+ 'Total Amount Awarded and Disbursed ' + (df['Total Amount Awarded and Disbursed']/1e3).astype(str)+'thousand'+'<br>'
limits = [(0,10),(10,100),(100,200),(200,500),(500,1000),(1000,3000)]
colors = ["lightgrey","rgb(255,65,54)","rgb(133,20,75)","rgb(255,133,27)","#ffb266","rgb(0,116,217)"]
Programs = []
scale = 6000

In [21]:
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(40,40,40)'),
            sizemode = 'area'
        ),
        name = '{0} - {1}'.format(limits[i][0],limits[i][1]) )
    Programs.append(program)

layout = dict(
        title = 'Administrative Discretionary Grants<br>(Click legend to toggle traces)',
        showlegend = True,
        geo = dict(
            scope='usa',
            projection=dict( type='albers usa' ),
            showland = True,
            landcolor = 'rgb(217, 217, 217)',
            subunitwidth=1,
            countrywidth=1,
            subunitcolor="rgb(255, 255, 255)",
            countrycolor="rgb(255, 255, 255)"
        ),
    )

In [22]:
fig = dict( data=Programs, layout=layout )
py.iplot( fig, validate=False, filename='d3-bubble-map-populations' )


Out[22]:

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 [ ]: