{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# World Power Consumption in 2014"
]
},
{
"cell_type": "code",
"execution_count": 107,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
""
],
"text/vnd.plotly.v1+html": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"import plotly.graph_objs as go \n",
"from plotly.offline import init_notebook_mode,iplot\n",
"init_notebook_mode(connected=True) "
]
},
{
"cell_type": "code",
"execution_count": 108,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"
\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" Country | \n",
" Power Consumption KWH | \n",
" Text | \n",
"
\n",
" \n",
" \n",
" \n",
" 0 | \n",
" China | \n",
" 5.523000e+12 | \n",
" China 5,523,000,000,000 | \n",
"
\n",
" \n",
" 1 | \n",
" United States | \n",
" 3.832000e+12 | \n",
" United 3,832,000,000,000 | \n",
"
\n",
" \n",
" 2 | \n",
" European | \n",
" 2.771000e+12 | \n",
" European 2,771,000,000,000 | \n",
"
\n",
" \n",
" 3 | \n",
" Russia | \n",
" 1.065000e+12 | \n",
" Russia 1,065,000,000,000 | \n",
"
\n",
" \n",
" 4 | \n",
" Japan | \n",
" 9.210000e+11 | \n",
" Japan 921,000,000,000 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" Country Power Consumption KWH Text\n",
"0 China 5.523000e+12 China 5,523,000,000,000\n",
"1 United States 3.832000e+12 United 3,832,000,000,000\n",
"2 European 2.771000e+12 European 2,771,000,000,000\n",
"3 Russia 1.065000e+12 Russia 1,065,000,000,000\n",
"4 Japan 9.210000e+11 Japan 921,000,000,000"
]
},
"execution_count": 108,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Import the dataset\n",
"import pandas as pd\n",
"df = pd.read_csv('2014_World_Power_Consumption')\n",
"df.head(5)"
]
},
{
"cell_type": "code",
"execution_count": 109,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"data = dict(type = 'choropleth',\n",
" colorscale = 'Electric',\n",
" reversescale = True,\n",
" locations = df['Country'],\n",
" locationmode = 'country names',\n",
" z = df['Power Consumption KWH'],\n",
" text = df['Country'],\n",
" colorbar = {'title': '2014 Power Consumption in KWH'})"
]
},
{
"cell_type": "code",
"execution_count": 110,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"layout = dict(title = '2014 Power Consumption in KWH',\n",
" geo = dict (showframe = False, projection = {'type': 'natural earth'}))"
]
},
{
"cell_type": "code",
"execution_count": 111,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"choromap = go.Figure(data=[data], layout=layout)"
]
},
{
"cell_type": "code",
"execution_count": 112,
"metadata": {
"scrolled": false
},
"outputs": [
{
"data": {
"application/vnd.plotly.v1+json": {
"data": [
{
"colorbar": {
"title": "2014 Power Consumption in KWH"
},
"colorscale": "Electric",
"locationmode": "country names",
"locations": [
"China",
"United States",
"European",
"Russia",
"Japan",
"India",
"Germany",
"Canada",
"Brazil",
"Korea,",
"France",
"United Kingdom",
"Italy",
"Taiwan",
"Spain",
"Mexico",
"Saudi",
"Australia",
"South",
"Turkey",
"Iran",
"Indonesia",
"Ukraine",
"Thailand",
"Poland",
"Egypt",
"Sweden",
"Norway",
"Malaysia",
"Argentina",
"Netherlands",
"Vietnam",
"Venezuela",
"United Arab Emirates",
"Finland",
"Belgium",
"Kazakhstan",
"Pakistan",
"Philippines",
"Austria",
"Chile",
"Czechia",
"Israel",
"Switzerland",
"Greece",
"Iraq",
"Romania",
"Kuwait",
"Colombia",
"Singapore",
"Portugal",
"Uzbekistan",
"Hong",
"Algeria",
"Bangladesh",
"New",
"Bulgaria",
"Belarus",
"Peru",
"Denmark",
"Qatar",
"Slovakia",
"Libya",
"Serbia",
"Morocco",
"Syria",
"Nigeria",
"Ireland",
"Hungary",
"Oman",
"Ecuador",
"Puerto",
"Azerbaijan",
"Croatia",
"Iceland",
"Cuba",
"Korea,",
"Dominican",
"Jordan",
"Tajikistan",
"Tunisia",
"Slovenia",
"Lebanon",
"Bosnia",
"Turkmenistan",
"Bahrain",
"Mozambique",
"Ghana",
"Sri",
"Kyrgyzstan",
"Lithuania",
"Uruguay",
"Costa",
"Guatemala",
"Georgia",
"Trinidad",
"Zambia",
"Paraguay",
"Albania",
"Burma",
"Estonia",
"Congo,",
"Panama",
"Latvia",
"Macedonia",
"Zimbabwe",
"Kenya",
"Bolivia",
"Luxembourg",
"Sudan",
"El",
"Cameroon",
"West",
"Ethiopia",
"Armenia",
"Honduras",
"Angola",
"Cote",
"Tanzania",
"Nicaragua",
"Moldova",
"Cyprus",
"Macau",
"Namibia",
"Mongolia",
"Afghanistan",
"Yemen",
"Brunei",
"Cambodia",
"Montenegro",
"Nepal",
"Botswana",
"Papua",
"Jamaica",
"Kosovo",
"Laos",
"Uganda",
"New",
"Mauritius",
"Senegal",
"Bhutan",
"Malawi",
"Madagascar",
"Bahamas,",
"Gabon",
"Suriname",
"Guam",
"Liechtenstein",
"Swaziland",
"Burkina",
"Togo",
"Curacao",
"Mauritania",
"Barbados",
"Niger",
"Aruba",
"Benin",
"Guinea",
"Mali",
"Fiji",
"Congo,",
"Virgin",
"Lesotho",
"South",
"Bermuda",
"French",
"Jersey",
"Belize",
"Andorra",
"Guyana",
"Cayman",
"Haiti",
"Rwanda",
"Saint",
"Djibouti",
"Seychelles",
"Somalia",
"Antigua",
"Greenland",
"Cabo",
"Eritrea",
"Burundi",
"Liberia",
"Maldives",
"Faroe",
"Gambia,",
"Chad",
"Micronesia,",
"Grenada",
"Central",
"Turks",
"Gibraltar",
"American",
"Sierra",
"Saint",
"Saint",
"Timor-Leste",
"Equatorial",
"Samoa",
"Dominica",
"Western",
"Solomon",
"Sao",
"British",
"Vanuatu",
"Guinea-Bissau",
"Tonga",
"Saint",
"Comoros",
"Cook",
"Kiribati",
"Montserrat",
"Nauru",
"Falkland",
"Saint",
"Niue",
"Gaza",
"Malta",
"Northern"
],
"reversescale": true,
"text": [
"China",
"United States",
"European",
"Russia",
"Japan",
"India",
"Germany",
"Canada",
"Brazil",
"Korea,",
"France",
"United Kingdom",
"Italy",
"Taiwan",
"Spain",
"Mexico",
"Saudi",
"Australia",
"South",
"Turkey",
"Iran",
"Indonesia",
"Ukraine",
"Thailand",
"Poland",
"Egypt",
"Sweden",
"Norway",
"Malaysia",
"Argentina",
"Netherlands",
"Vietnam",
"Venezuela",
"United Arab Emirates",
"Finland",
"Belgium",
"Kazakhstan",
"Pakistan",
"Philippines",
"Austria",
"Chile",
"Czechia",
"Israel",
"Switzerland",
"Greece",
"Iraq",
"Romania",
"Kuwait",
"Colombia",
"Singapore",
"Portugal",
"Uzbekistan",
"Hong",
"Algeria",
"Bangladesh",
"New",
"Bulgaria",
"Belarus",
"Peru",
"Denmark",
"Qatar",
"Slovakia",
"Libya",
"Serbia",
"Morocco",
"Syria",
"Nigeria",
"Ireland",
"Hungary",
"Oman",
"Ecuador",
"Puerto",
"Azerbaijan",
"Croatia",
"Iceland",
"Cuba",
"Korea,",
"Dominican",
"Jordan",
"Tajikistan",
"Tunisia",
"Slovenia",
"Lebanon",
"Bosnia",
"Turkmenistan",
"Bahrain",
"Mozambique",
"Ghana",
"Sri",
"Kyrgyzstan",
"Lithuania",
"Uruguay",
"Costa",
"Guatemala",
"Georgia",
"Trinidad",
"Zambia",
"Paraguay",
"Albania",
"Burma",
"Estonia",
"Congo,",
"Panama",
"Latvia",
"Macedonia",
"Zimbabwe",
"Kenya",
"Bolivia",
"Luxembourg",
"Sudan",
"El",
"Cameroon",
"West",
"Ethiopia",
"Armenia",
"Honduras",
"Angola",
"Cote",
"Tanzania",
"Nicaragua",
"Moldova",
"Cyprus",
"Macau",
"Namibia",
"Mongolia",
"Afghanistan",
"Yemen",
"Brunei",
"Cambodia",
"Montenegro",
"Nepal",
"Botswana",
"Papua",
"Jamaica",
"Kosovo",
"Laos",
"Uganda",
"New",
"Mauritius",
"Senegal",
"Bhutan",
"Malawi",
"Madagascar",
"Bahamas,",
"Gabon",
"Suriname",
"Guam",
"Liechtenstein",
"Swaziland",
"Burkina",
"Togo",
"Curacao",
"Mauritania",
"Barbados",
"Niger",
"Aruba",
"Benin",
"Guinea",
"Mali",
"Fiji",
"Congo,",
"Virgin",
"Lesotho",
"South",
"Bermuda",
"French",
"Jersey",
"Belize",
"Andorra",
"Guyana",
"Cayman",
"Haiti",
"Rwanda",
"Saint",
"Djibouti",
"Seychelles",
"Somalia",
"Antigua",
"Greenland",
"Cabo",
"Eritrea",
"Burundi",
"Liberia",
"Maldives",
"Faroe",
"Gambia,",
"Chad",
"Micronesia,",
"Grenada",
"Central",
"Turks",
"Gibraltar",
"American",
"Sierra",
"Saint",
"Saint",
"Timor-Leste",
"Equatorial",
"Samoa",
"Dominica",
"Western",
"Solomon",
"Sao",
"British",
"Vanuatu",
"Guinea-Bissau",
"Tonga",
"Saint",
"Comoros",
"Cook",
"Kiribati",
"Montserrat",
"Nauru",
"Falkland",
"Saint",
"Niue",
"Gaza",
"Malta",
"Northern"
],
"type": "choropleth",
"z": [
5523000000000,
3832000000000,
2771000000000,
1065000000000,
921000000000,
864700000000,
540100000000,
511000000000,
483500000000,
482400000000,
451100000000,
319100000000,
303100000000,
249500000000,
243100000000,
234000000000,
231600000000,
222600000000,
211600000000,
197000000000,
195300000000,
167500000000,
159800000000,
155900000000,
139000000000,
135600000000,
130500000000,
126400000000,
118500000000,
117100000000,
116800000000,
108300000000,
97690000000,
93280000000,
82040000000,
81890000000,
80290000000,
78890000000,
75270000000,
69750000000,
63390000000,
60550000000,
59830000000,
58010000000,
57730000000,
53410000000,
50730000000,
50000000000,
49380000000,
47180000000,
46250000000,
45210000000,
44210000000,
42870000000,
41520000000,
40300000000,
37990000000,
37880000000,
35690000000,
31960000000,
30530000000,
28360000000,
27540000000,
26910000000,
26700000000,
25700000000,
24780000000,
24240000000,
21550000000,
20360000000,
19020000000,
18620000000,
17790000000,
16970000000,
16940000000,
16200000000,
16000000000,
15140000000,
14560000000,
14420000000,
13310000000,
13020000000,
12940000000,
12560000000,
11750000000,
11690000000,
11280000000,
10580000000,
10170000000,
9943000000,
9664000000,
9559000000,
8987000000,
8915000000,
8468000000,
8365000000,
8327000000,
8125000000,
7793000000,
7765000000,
7417000000,
7292000000,
7144000000,
7141000000,
6960000000,
6831000000,
6627000000,
6456000000,
6108000000,
5665000000,
5665000000,
5535000000,
5312000000,
5227000000,
5043000000,
5036000000,
4842000000,
4731000000,
4545000000,
4412000000,
4305000000,
4296000000,
4291000000,
4238000000,
4204000000,
3893000000,
3838000000,
3766000000,
3553000000,
3465000000,
3239000000,
3213000000,
3116000000,
3008000000,
2887000000,
2874000000,
2821000000,
2716000000,
2658000000,
2586000000,
2085000000,
2027000000,
1883000000,
1716000000,
1680000000,
1572000000,
1566000000,
1360000000,
1295000000,
985500000,
976000000,
968000000,
962600000,
938000000,
930200000,
920700000,
911000000,
903000000,
882600000,
777600000,
740000000,
723500000,
707000000,
694100000,
664200000,
652900000,
630100000,
605000000,
562400000,
558000000,
545900000,
452000000,
365500000,
336400000,
311600000,
293900000,
293000000,
293000000,
292000000,
285500000,
284000000,
282900000,
276900000,
267100000,
261300000,
218600000,
190700000,
178600000,
178000000,
168300000,
167400000,
160000000,
146000000,
134900000,
130200000,
127400000,
125300000,
93000000,
90400000,
89750000,
83700000,
79050000,
60450000,
51150000,
49290000,
46500000,
44640000,
39990000,
39990000,
28950000,
24180000,
23250000,
23250000,
11160000,
7440000,
2790000,
202000,
174700,
48300
]
}
],
"layout": {
"geo": {
"projection": {
"type": "natural earth"
},
"showframe": false
},
"title": "2014 Power Consumption in KWH"
}
},
"text/html": [
""
],
"text/vnd.plotly.v1+html": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"iplot(choromap,validate=False)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"China and USA were the major power consuming nations in 2014. "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# 2012 General Election Voting Data"
]
},
{
"cell_type": "code",
"execution_count": 123,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"elect = pd.read_csv('2012_Election_Data')"
]
},
{
"cell_type": "code",
"execution_count": 141,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" Year | \n",
" ICPSR State Code | \n",
" Alphanumeric State Code | \n",
" State | \n",
" VEP Total Ballots Counted | \n",
" VEP Highest Office | \n",
" VAP Highest Office | \n",
" Total Ballots Counted | \n",
" Highest Office | \n",
" Voting-Eligible Population (VEP) | \n",
" Voting-Age Population (VAP) | \n",
" % Non-citizen | \n",
" Prison | \n",
" Probation | \n",
" Parole | \n",
" Total Ineligible Felon | \n",
" State Abv | \n",
"
\n",
" \n",
" \n",
" \n",
" 0 | \n",
" 2012 | \n",
" 41 | \n",
" 1 | \n",
" Alabama | \n",
" NaN | \n",
" 58.6% | \n",
" 56.0% | \n",
" NaN | \n",
" 2,074,338 | \n",
" 3,539,217 | \n",
" 3707440.0 | \n",
" 2.6% | \n",
" 32,232 | \n",
" 57,993 | \n",
" 8,616 | \n",
" 71,584 | \n",
" AL | \n",
"
\n",
" \n",
" 1 | \n",
" 2012 | \n",
" 81 | \n",
" 2 | \n",
" Alaska | \n",
" 58.9% | \n",
" 58.7% | \n",
" 55.3% | \n",
" 301,694 | \n",
" 300,495 | \n",
" 511,792 | \n",
" 543763.0 | \n",
" 3.8% | \n",
" 5,633 | \n",
" 7,173 | \n",
" 1,882 | \n",
" 11,317 | \n",
" AK | \n",
"
\n",
" \n",
" 2 | \n",
" 2012 | \n",
" 61 | \n",
" 3 | \n",
" Arizona | \n",
" 53.0% | \n",
" 52.6% | \n",
" 46.5% | \n",
" 2,323,579 | \n",
" 2,306,559 | \n",
" 4,387,900 | \n",
" 4959270.0 | \n",
" 9.9% | \n",
" 35,188 | \n",
" 72,452 | \n",
" 7,460 | \n",
" 81,048 | \n",
" AZ | \n",
"
\n",
" \n",
" 3 | \n",
" 2012 | \n",
" 42 | \n",
" 4 | \n",
" Arkansas | \n",
" 51.1% | \n",
" 50.7% | \n",
" 47.7% | \n",
" 1,078,548 | \n",
" 1,069,468 | \n",
" 2,109,847 | \n",
" 2242740.0 | \n",
" 3.5% | \n",
" 14,471 | \n",
" 30,122 | \n",
" 23,372 | \n",
" 53,808 | \n",
" AR | \n",
"
\n",
" \n",
" 4 | \n",
" 2012 | \n",
" 71 | \n",
" 5 | \n",
" California | \n",
" 55.7% | \n",
" 55.1% | \n",
" 45.1% | \n",
" 13,202,158 | \n",
" 13,038,547 | \n",
" 23,681,837 | \n",
" 28913129.0 | \n",
" 17.4% | \n",
" 119,455 | \n",
" 0 | \n",
" 89,287 | \n",
" 208,742 | \n",
" CA | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" Year ICPSR State Code Alphanumeric State Code State \\\n",
"0 2012 41 1 Alabama \n",
"1 2012 81 2 Alaska \n",
"2 2012 61 3 Arizona \n",
"3 2012 42 4 Arkansas \n",
"4 2012 71 5 California \n",
"\n",
" VEP Total Ballots Counted VEP Highest Office VAP Highest Office \\\n",
"0 NaN 58.6% 56.0% \n",
"1 58.9% 58.7% 55.3% \n",
"2 53.0% 52.6% 46.5% \n",
"3 51.1% 50.7% 47.7% \n",
"4 55.7% 55.1% 45.1% \n",
"\n",
" Total Ballots Counted Highest Office Voting-Eligible Population (VEP) \\\n",
"0 NaN 2,074,338 3,539,217 \n",
"1 301,694 300,495 511,792 \n",
"2 2,323,579 2,306,559 4,387,900 \n",
"3 1,078,548 1,069,468 2,109,847 \n",
"4 13,202,158 13,038,547 23,681,837 \n",
"\n",
" Voting-Age Population (VAP) % Non-citizen Prison Probation Parole \\\n",
"0 3707440.0 2.6% 32,232 57,993 8,616 \n",
"1 543763.0 3.8% 5,633 7,173 1,882 \n",
"2 4959270.0 9.9% 35,188 72,452 7,460 \n",
"3 2242740.0 3.5% 14,471 30,122 23,372 \n",
"4 28913129.0 17.4% 119,455 0 89,287 \n",
"\n",
" Total Ineligible Felon State Abv \n",
"0 71,584 AL \n",
"1 11,317 AK \n",
"2 81,048 AZ \n",
"3 53,808 AR \n",
"4 208,742 CA "
]
},
"execution_count": 141,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"elect.head()"
]
},
{
"cell_type": "code",
"execution_count": 168,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"data = dict(type='choropleth',\n",
" colorscale = 'Viridis',\n",
" reversescale = True,\n",
" locations = elect['State Abv'],\n",
" z = elect['Voting-Age Population (VAP)'],\n",
" locationmode = 'USA-states',\n",
" text = elect['State'],\n",
" marker = dict(line = dict(color = 'rgb(12,12,12)',width = 1)),\n",
" colorbar = {'title':\"Voting-Age Population (VAP)\"}\n",
" ) "
]
},
{
"cell_type": "code",
"execution_count": 169,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"layout = dict(title = '2012 General Election Voting Data',\n",
" geo = dict(scope='usa',showlakes = True, lakecolor = 'rgb(85,173,240)'))"
]
},
{
"cell_type": "code",
"execution_count": 170,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"choromap1 = go.Figure(data = [data],layout = layout)"
]
},
{
"cell_type": "code",
"execution_count": 171,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.plotly.v1+json": {
"data": [
{
"colorbar": {
"title": "Voting-Age Population (VAP)"
},
"colorscale": "Viridis",
"locationmode": "USA-states",
"locations": [
"AL",
"AK",
"AZ",
"AR",
"CA",
"CO",
"CT",
"DE",
"District of Columbia",
"FL",
"GA",
"HI",
"ID",
"IL",
"IN",
"IA",
"KS",
"KY",
"LA",
"ME",
"MD",
"MA",
"MI",
"MN",
"MS",
"MO",
"MT",
"NE",
"NV",
"NH",
"NJ",
"NM",
"NY",
"NC",
"ND",
"OH",
"OK",
"OR",
"PA",
"RI",
"SC",
"SD",
"TN",
"TX",
"UT",
"VT",
"VA",
"WA",
"WV",
"WI",
"WY"
],
"marker": {
"line": {
"color": "rgb(12,12,12)",
"width": 1
}
},
"reversescale": true,
"text": [
"Alabama",
"Alaska",
"Arizona",
"Arkansas",
"California",
"Colorado",
"Connecticut",
"Delaware",
"District of Columbia",
"Florida",
"Georgia",
"Hawaii",
"Idaho",
"Illinois",
"Indiana",
"Iowa",
"Kansas",
"Kentucky",
"Louisiana",
"Maine",
"Maryland",
"Massachusetts",
"Michigan",
"Minnesota",
"Mississippi",
"Missouri",
"Montana",
"Nebraska",
"Nevada",
"New Hampshire",
"New Jersey",
"New Mexico",
"New York",
"North Carolina",
"North Dakota",
"Ohio",
"Oklahoma",
"Oregon",
"Pennsylvania",
"Rhode Island",
"South Carolina",
"South Dakota",
"Tennessee",
"Texas",
"Utah",
"Vermont",
"Virginia",
"Washington",
"West Virginia",
"Wisconsin",
"Wyoming"
],
"type": "choropleth",
"z": [
3707440,
543763,
4959270,
2242740,
28913129,
3981208,
2801375,
715708,
528848,
15380947,
7452696,
1088335,
1173727,
9827043,
4960376,
2356209,
2162442,
3368684,
3495847,
1064779,
4553853,
5263550,
7625576,
4114820,
2246931,
4628500,
785454,
1396507,
2105976,
1047978,
6847503,
1573400,
15344671,
7496980,
549955,
8896930,
2885093,
3050747,
10037099,
834983,
3662322,
631472,
4976284,
19185395,
1978956,
502242,
6348827,
5329782,
1472642,
4417273,
441726
]
}
],
"layout": {
"geo": {
"lakecolor": "rgb(85,173,240)",
"scope": "usa",
"showlakes": true
},
"title": "2012 General Election Voting Data"
}
},
"text/html": [
""
],
"text/vnd.plotly.v1+html": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"iplot(choromap1)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"As we can see California, Texas, New York, and Florida are the major states where voting population resides."
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.2"
}
},
"nbformat": 4,
"nbformat_minor": 2
}