Library and Packages


In [2]:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import plotly
import plotly.plotly as py
import plotly.figure_factory as ff

Loading Precipitation Data


In [3]:
df = pd.read_csv('new_climate_data.csv')
df.drop('Unnamed: 0', axis = 1)

Visualization of US Average Daily Precipitation Data


In [12]:
## [12025, 30113, 51560, 51780] Cannot be show
colorscale = ["#d2e3f3","#9ecae1",
              "#85bcdb","#4292c6","#3082be","#2171b5","#1361a9",
              "#08519c","#0b4083","#08306b"]

endpts =[1,2,3,4,5,6,7,8]
fips = df['FIPS'].tolist()
values = df['Avg Daily Precipitation (mm)'].tolist()

fig = ff.create_choropleth(
    fips=fips, values=values,
    binning_endpoints=endpts,
    colorscale=colorscale,
    show_state_data=False,
    show_hover=True, centroid_marker={'opacity': 0},
    asp=2.9, title='US Average Daily Precipitation',
    legend_title='Avg Daily Precipitation (mm)'
)
py.iplot(fig, filename='choropleth_full_usa')


/Users/AkshayKale/anaconda3/lib/python3.6/site-packages/plotly/figure_factory/_county_choropleth.py:763: UserWarning:

Unrecognized FIPS Values

Whoops! It looks like you are trying to pass at least one FIPS value that is not in our shapefile of FIPS and data for the counties. Your choropleth will still show up but these counties cannot be shown.
Unrecognized FIPS are: [12025, 30113, 51560, 51780]

The draw time for this plot will be slow for clients without much RAM.
/Users/AkshayKale/anaconda3/lib/python3.6/site-packages/plotly/api/v1/clientresp.py:40: UserWarning:

Estimated Draw Time Slow

Out[12]:

In [38]:
categories = pd.cut(np.array(df['Avg Daily Precipitation (mm)']),4)
df['Category'] = list(categories)
groupby_category = df.groupby(['Category','State'])['County'].count()

Grouping Counties by Category and States


In [43]:
groupby_category


Out[43]:
Category        State
(0.243, 2.098]   AZ       15
                 CA       34
                 CO       61
                 IA        5
                 ID       33
                 KS       46
                 MI        7
                 MN       54
                 MT       52
                 ND       53
                 NE       69
                 NM       33
                 NV       17
                 OK       17
                 OR       17
                 SD       66
                 TX      134
                 UT       29
                 WA       19
                 WY       21
(2.098, 3.945]   AL       58
                 AR       73
                 CA       22
                 CO        2
                 CT        8
                 DC        1
                 DE        3
                 FL       59
                 GA      153
                 IA       94
                        ... 
                 NJ       21
                 NY       62
                 OH       88
                 OK       60
                 OR        6
                 PA       67
                 RI        5
                 SC       45
                 TN       95
                 TX      120
                 VA      136
                 VT       14
                 WA        5
                 WI       72
                 WV       55
                 WY        1
(3.945, 5.792]   AL        9
                 AR        2
                 CA        1
                 FL        8
                 GA        6
                 LA       33
                 MS       29
                 NC        6
                 OR        9
                 SC        1
                 WA        9
(5.792, 7.64]    CA        1
                 OR        4
                 WA        6
Name: County, Length: 77, dtype: int64

In [ ]:
## county precp data and ## condition rating of the county ## deterioration rates