In [1]:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
In [2]:
import plotly
import plotly.plotly as py
from plotly.graph_objs import *
import pandas as pd
In [3]:
plotly.tools.set_credentials_file(username='jxljiang221', api_key='LOONcFbgZszSxdiuB3Kn')
In [4]:
df2 = pd.read_csv('C:\\Users\\xiaoliang\\Desktop\\DiscGrants96to13-2017_04_10_19_27_08.csv',encoding='iso-8859-1',sep='\t')
df2.head()
Out[4]:
In [8]:
df2.columns
Out[8]:
In [7]:
df2.describe()
Out[7]:
In [5]:
df2['Text'] = df2['Institution'] + '<br>' + df2['Program'] + '<br>' + df2['ProgramType'] + 'Total Award' + (df2['AwardTotal']/1e3).astype(str)+ ' thousand'
#df2['text'] = df2['Institution'] + 'Total Award' + (df2['AwardTotal']/1e3).astype(str)+ ' thousand'
limits = [(0,10),(10,100),(100,200),(200,500),(500,1000),(1000,3000)]
#colors = ["#ffcccc","#ffddcc","#ffeecc","#ffffcc","#eeffcc","#ddffcc"]
colors = ["e0e0e0","#66b2ff","#66ff66","#ffff66","#ffb266","#ff6666"]
institutions = []
scale = 6000
for i in range(len(limits)):
subdf2=df2[((df2['AwardTotal']/1e3)<limits[i][1])&((df2['AwardTotal']/1e3)>limits[i][0])]
institution = dict(
type = 'scattergeo',
locationmode = 'USA-states',
lon = subdf2['Longitude'],
lat = subdf2['Latitude'],
text = subdf2['Text'],
marker = dict(
size = subdf2['AwardTotal']/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]) )
institutions.append(institution)
In [6]:
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)"
),
)
fig = dict( data=institutions, layout=layout )
py.iplot( fig, validate=False, filename='q2testworldmap' )
Out[6]:
In [20]:
df2['Text'] = df2['Institution'] + '<br>' + df2['Program'] + '<br>' + df2['ProgramType'] + '<br>'+ 'Total Award:' + (df2['AwardTotal']/1e3).astype(str)+ ' thousand'
#df2['text'] = df2['Institution'] + 'Total Award' + (df2['AwardTotal']/1e3).astype(str)+ ' thousand'
limits = [(0,10),(10,100),(100,200),(200,500),(500,1000),(1000,3000)]
#colors = ["#ffcccc","#ffddcc","#ffeecc","#ffffcc","#eeffcc","#ddffcc"]
colors = ["e0e0e0","#66b2ff","#66ff66","#ffff66","#ffb266","#ff6666"]
institutions = []
scale = 6000
for i in range(len(limits)):
subdf2=df2[((df2['AwardTotal']/1e3)<limits[i][1])&((df2['AwardTotal']/1e3)>limits[i][0])]
institution = dict(
type = 'scattergeo',
locationmode = 'USA-states',
lon = subdf2['Longitude'],
lat = subdf2['Latitude'],
text = subdf2['Text'],
marker = dict(
size = subdf2['AwardTotal']/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]) )
institutions.append(institution)
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)"
),
)
fig = dict( data=institutions, layout=layout )
py.iplot( fig, validate=False, filename='q2testworldmap' )
Out[20]:
In [52]:
df2['Text'] = 'Institution: ' + df2['Institution'] + '<br>' + 'Program: ' + df2['Program'] + '<br>' + 'Prgram Type: ' + df2['ProgramType'] + '<br>'+ 'Total Award:' + (df2['AwardTotal']/1e3).astype(str)+ ' thousand'
#df2['text'] = df2['Institution'] + 'Total Award' + (df2['AwardTotal']/1e3).astype(str)+ ' thousand'
limits = [(0,10000),(10000,100000),(100000,200000),(200000,500000),(500000,1000000),(1000000,3000000)]
#colors = ["#ffcccc","#ffddcc","#ffeecc","#ffffcc","#eeffcc","#ddffcc"]
colors = ["e0e0e0","#66b2ff","#66ff66","#ffff66","#ffb266","#ff6666"]
institutions = []
scale = 6000
for i in range(len(limits)):
subdf2=df2[((df2['AwardTotal'])<limits[i][1])&((df2['AwardTotal'])>limits[i][0])]
institution = dict(
type = 'scattergeo',
locationmode = 'USA-states',
lon = subdf2['Longitude'],
lat = subdf2['Latitude'],
text = subdf2['Text'],
marker = dict(
size = subdf2['AwardTotal']/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])+' thousand' )
institutions.append(institution)
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)"
),
)
fig = dict( data=institutions, layout=layout )
py.iplot( fig, validate=False, filename='q2testworldmap' )
In [43]:
institutions[4]['text']
Out[43]:
In [ ]: