Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Team04 Data Insights and Visualizations #10

Open
wants to merge 1 commit into
base: gh-pages
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified .DS_Store
Binary file not shown.
68 changes: 68 additions & 0 deletions TEAM04Files/Bar2Chart/Untitled.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"csv = pd.read_csv(\"military.csv\")"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
"csv = csv.sort_values('ST_NAME')"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
"csv.to_csv(\"military.csv\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"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.4"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
85 changes: 85 additions & 0 deletions TEAM04Files/Bar2Chart/javascript.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
var margin = {top: 40, right: 10, bottom: 180, left: 10},
width = 1000 - margin.left - margin.right,
height = 500 - margin.top - margin.bottom;

var formatPercent = d3.format(".0%");

var x = d3.scale.ordinal()
.rangeRoundBands([0, width], .1);

var y = d3.scale.linear()
.range([height, 0]);

var xAxis = d3.svg.axis()
.scale(x)
.orient("bottom");

var yAxis = d3.svg.axis()
.scale(y)
.orient("left")
.tickFormat(formatPercent);

var tip = d3.tip()
.attr('class', 'd3-tip')
.offset([-10, 0])
.html(function (d) {
return "<strong>STATE:</strong> <span style='color:red'>" + d.ST_NAME + "</span><br><strong>Military Base Count:</strong> <span style='color:red'>" + d.count + "</span>";
})

var svg = d3.select("body").append("svg")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom)
.append("g")
.attr("transform", "translate(" + margin.left + "," + margin.top + ")");

svg.call(tip);

d3.csv("military.csv", type, function (error, data) {
x.domain(data.map(function (d) {
return d.ST_NAME.slice(0,2);
}));
y.domain([0, d3.max(data, function (d) {
return d.count;
})]);

svg.append("g")
.attr("class", "x axis")
.attr("transform", "translate(0," + height + ")")
.call(xAxis);
// .selectAll("text")
// .style("text-anchor","end")
// .attr("transform","rotate(-90)");

svg.append("g")
.attr("class", "y axis")
.call(yAxis)
.append("text")
.attr("transform", "rotate(-90)")
.attr("y", 6)
.attr("dy", ".71em")
.style("text-anchor", "end")
.text("Count");

svg.selectAll(".bar")
.data(data)
.enter().append("rect")
.attr("class", "bar")
.attr("x", function (d) {
return x(d.ST_NAME.slice(0,2));
})
.attr("width", x.rangeBand())
.attr("y", function (d) {
return y(d.count);
})
.attr("height", function (d) {
return height - y(d.count);
})
.on('mouseover', tip.show)
.on('mouseout', tip.hide)

});

function type(d) {
d.count = +d.count;
return d;
}
50 changes: 50 additions & 0 deletions TEAM04Files/Bar2Chart/military.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
,Unnamed: 0,ST_NAME,count
11,220,ALABAMA,10
26,249,ALASKA,5
12,71,ARIZONA,9
23,204,ARKANSAS,6
0,123,CALIFORNIA,68
19,268,COLORADO,8
46,61,CONNECTICUT,1
48,278,DELAWARE,1
32,312,DISTRICT OF COLUMBIA,4
3,329,FLORIDA,17
6,108,GEORGIA,14
18,364,HAWAII,8
35,83,IDAHO,3
16,263,ILLINOIS,8
9,179,INDIANA,10
44,258,IOWA,1
21,374,KANSAS,6
29,80,KENTUCKY,5
30,78,LOUISIANA,5
33,197,MAINE,4
5,282,MARYLAND,14
14,250,MASSACHUSETTS,8
27,223,MICHIGAN,5
37,209,MINNESOTA,3
15,177,MISSISSIPPI,8
17,261,MISSOURI,8
43,239,MONTANA,1
36,389,NEBRASKA,3
34,325,NEVADA,4
25,241,NEW JERSEY,6
28,192,NEW MEXICO,5
7,196,NEW YORK,11
20,400,NORTH CAROLINA,6
41,339,NORTH DAKOTA,2
31,328,OHIO,5
24,193,OKLAHOMA,6
39,277,OREGON,2
8,102,PENNSYLVANIA,11
42,349,PUERTO RICO,2
40,89,RHODE ISLAND,2
10,190,SOUTH CAROLINA,10
47,207,SOUTH DAKOTA,1
22,290,TENNESSEE,6
2,56,TEXAS,26
13,240,UTAH,8
1,55,VIRGINIA,29
4,47,WASHINGTON,16
38,332,WISCONSIN,3
45,292,WYOMING,1
73 changes: 73 additions & 0 deletions TEAM04Files/Bar2Chart/military_bar.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<style>

body {
font: 10px sans-serif;
}

.axis path,
.axis line {
fill: none;
stroke: #000;
shape-rendering: crispEdges;
}

.bar {
fill: darkslateblue;
}

.bar:hover {
fill: orangered;
}

.x.axis path {
display: none;
}

.d3-tip {
line-height: 1;
font-weight: bold;
padding: 12px;
background: rgba(0, 0, 0, 0.8);
color: #fff;
border-radius: 2px;
}

/* Creates a small triangle extender for the tooltip */
.d3-tip:after {
box-sizing: border-box;
display: inline;
font-size: 10px;
width: 100%;
line-height: 1;
color: rgba(0, 0, 0, 0.8);
content: "\25BC";
position: absolute;
text-align: center;
}

/* Style northward tooltips differently */
.d3-tip.n:after {
margin: -1px 0 0 0;
top: 100%;
left: 0;
}
</style>
<title>Bar Chart</title>
</head>
<body>
<h1>
Number of Military Bases per State.
</h1>
<h1>
Number of Military Bases per State.
</h1>
<div id="chart"></div>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script src="http://labratrevenge.com/d3-tip/javascripts/d3.tip.v0.6.3.js"></script>
<script type="text/javascript" src="javascript.js"></script>
</body>
</html>
77 changes: 77 additions & 0 deletions TEAM04Files/BarChart/Population_bar.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [],
"source": [
"csv = pd.read_csv(\"city-pop.csv\")"
]
},
{
"cell_type": "code",
"execution_count": 27,
"metadata": {},
"outputs": [],
"source": [
"csv1 = csv.sort_values(by = [\"population\"], ascending = False).drop_duplicates().head(10)\n"
]
},
{
"cell_type": "code",
"execution_count": 28,
"metadata": {},
"outputs": [],
"source": [
"csv1 = csv1.sort_values(by = [\"city\"])"
]
},
{
"cell_type": "code",
"execution_count": 30,
"metadata": {},
"outputs": [],
"source": [
"csv1.to_csv(\"city-pop-top10.csv\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"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.4"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
32 changes: 32 additions & 0 deletions TEAM04Files/BarChart/Population_bar_script.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@

# coding: utf-8

# In[1]:


import pandas as pd


# In[12]:


csv = pd.read_csv("city-pop.csv")


# In[27]:


csv1 = csv.sort_values(by = ["population"], ascending = False).drop_duplicates().head(10)


# In[28]:


csv1 = csv1.sort_values(by = ["city"])


# In[30]:


csv1.to_csv("city-pop-top10.csv")

Empty file.
Loading