Skip to content

Instantly share code, notes, and snippets.

@sudipto80
Created October 28, 2014 02:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sudipto80/98f6d3add50e9cfd3900 to your computer and use it in GitHub Desktop.
Save sudipto80/98f6d3add50e9cfd3900 to your computer and use it in GitHub Desktop.
Squirrel Example : Finding Gender Ration in North America
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