import plotly.graph_objs as go
from plotly.offline import init_notebook_mode,iplot
init_notebook_mode(connected=True)
Import pandas and read the csv file: 2014_World_Power_Consumption
import pandas as pd
df = pd.read_csv('2014_World_Power_Consumption')
Check the header of the DataFrame.
df.head()
Referencing the lecture notes, create a Choropleth Plot of the Power Consumption for Countries using the data and layout dictionary.
data = dict(type = 'choropleth',
locations = df['Country'],
locationmode = "country names",
colorscale= 'Portland',
text= df['Text'],
z=df['Power Consumption KWH'],
colorbar = {'title':'KWH'})
layout = dict(
title = '2014 World Power Consumption',
geo = dict(
showframe = False,
projection = {'type':'Mercator'}
)
)
choromap = go.Figure(data = [data],layout = layout)
iplot(choromap,validate=False)
Import the 2012_Election_Data csv file using pandas.
edata2012 = pd.read_csv('2012_Election_Data')
Check the header of the DataFrame.
edata2012.head()
Plot the Voting-Age Population (VAP) per state, with additional information of felonies unable to vote in each state on mousover
data = dict(type = 'choropleth',
locations = edata2012['State Abv'],
locationmode = 'USA-states',
colorscale= 'Reds',
text= edata2012['Total Ineligible Felon'],
z=edata2012['Voting-Age Population (VAP)'],
colorbar = {'title':'VAP'})
layout = dict(
title = '2012 Voting-Age Population with Total Ineligible Felon Mouseover',
geo = dict(scope='usa',showlakes = True,lakecolor = 'rgb(85,173,240)')
)
choromap = go.Figure(data = [data],layout = layout)
iplot(choromap,validate=False)