from urllib.request import urlopen
import json
import pandas as pd
import plotly.express as px

with urlopen('https://raw.githubusercontent.com/plotly/datasets/master/geojson-counties-fips.json') as response:
    counties = json.load(response)
field = 'mean_work_travel_2017'
df = pd.read_csv('county_complete.csv',
                 dtype={'fips': str},
                 header=0)
df['fips'] = df['fips'].str.pad(5, 'left', '0')
df['county'] = df['state'] + ', ' + df['name']
dfx = df[['fips', field, 'county']]
fig = px.choropleth(dfx, geojson=counties,
                    locations='fips',
                    color=field,
                    color_continuous_scale='RdBu',
                    range_color=(min(dfx[field]), max(dfx[field])),
                    scope='usa',
                    hover_data={'county': True}
                    )
fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0})
fig.show()
