In [1]:
import numpy as np
import os
import zipcode
import pandas as pd
In [2]:
DIR = os.getcwd() + "/../data/"
df = pd.read_csv(DIR + 'raw/loan.csv', low_memory=False)
df.head()
Out[2]:
In [3]:
int_rate_df = df[['int_rate', 'addr_state']].groupby('addr_state').mean()
In [4]:
int_rate_df = int_rate_df.reset_index()
In [5]:
import plotly.plotly as py
scl = [[0.0, 'rgb(242,240,247)'],[0.2, 'rgb(218,218,235)'],[0.4, 'rgb(188,189,220)'],\
[0.6, 'rgb(158,154,200)'],[0.8, 'rgb(117,107,177)'],[1.0, 'rgb(84,39,143)']]
In [8]:
data = [ dict(
type='choropleth',
colorscale = scl,
autocolorscale = True,
locations = int_rate_df['addr_state'],
z = int_rate_df['int_rate'].astype(float),
locationmode = 'USA-states',
marker = dict(
line = dict (
color = 'rgb(255,255,255)',
width = 2
) ),
colorbar = dict(
title = "Interest Rate")
) ]
layout = dict(
title = 'Interest Rates by States in %',
geo = dict(
scope='usa',
projection=dict( type='albers usa' ),
showlakes = True,
lakecolor = 'rgb(255, 255, 255)'),
)
fig = dict( data=data, layout=layout )
py.iplot( fig, filename='Interest Rates by State in %' )
Out[8]:
In [ ]: