In [2]:
import plotly.graph_objs as go
from plotly.offline import init_notebook_mode,iplot
init_notebook_mode(connected=True)
import pandas as pd
Import pandas and read the csv file: 2014_World_Power_Consumption
In [4]:
df = pd.read_csv('./2014_World_Power_Consumption')
df.head()
Out[4]:
Referencing the lecture notes, create a Choropleth Plot of the Power Consumption for Countries using the data and layout dictionary.
In [12]:
data = {'type':'choropleth', 'locations':df['Country'],'locationmode':'country names',
'z':df['Power Consumption KWH'], 'text':df['Text']}
layout={'title':'World power consumption',
'geo':{'showframe':True, 'projection':{'type':'Mercator'}}}
In [13]:
choromap = go.Figure(data = [data],layout = layout)
iplot(choromap,validate=False)
In [15]:
df2 = pd.read_csv('./2012_Election_Data')
Check the head of the DataFrame.
In [16]:
df2.head()
Out[16]:
Now create a plot that displays the Voting-Age Population (VAP) per state. If you later want to play around with other columns, make sure you consider their data type. VAP has already been transformed to a float for you.
In [21]:
data = {'type':'choropleth', 'locations':df2['State Abv'],'locationmode':'USA-states',
'z':df2['% Non-citizen'], 'text':df2['% Non-citizen']}
layout={'geo':{'scope':'usa'}}
In [22]:
choromap = go.Figure(data = [data],layout = layout)
iplot(choromap,validate=False)