Created
October 28, 2014 02:39
-
-
Save sudipto80/98f6d3add50e9cfd3900 to your computer and use it in GitHub Desktop.
Squirrel Example : Finding Gender Ration in North America
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Table births = DataAcquisition.LoadCSV(@"..\..\births.csv"); | |
var splits = births.SplitOn("sex"); | |
var boys = splits["boy"].Aggregate("state").Drop("year"); | |
var girls = splits["girl"].Aggregate("state").Drop("year"); | |
Table combined = new Table(); | |
combined.AddColumn("State", boys["state"]); | |
combined.AddColumn("Boys", boys["births"]); | |
combined.AddColumn("Girls", girls["births"]); | |
combined.AddColumn("Difference", "[Boys]-[Girls]", 4); | |
combined.AddColumn("GenderRatio", "[Girls]/[Boys]", 4); | |
//Showing 5 stats with lowest gender ratio at the end of 2006. | |
string tab = combined.Pick("State", "GenderRatio") | |
.SortBy("GenderRatio") | |
.Top(5) | |
.ToHTMLTable(); | |
StreamWriter sw = new StreamWriter("temp.htm"); | |
sw.WriteLine("<html><h2>Gender Ratio in North America by the end of 2006</h2>" + tab + "</html>"); | |
sw.Close(); | |
System.Diagnostics.Process.Start("temp.htm"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment