This file contains hidden or 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
#r @"C:\Users\mukhsudi\Documents\GitHub\SquirrelLatest\ConsoleApplication2\bin\Debug\TableAPI.dll" | |
//type NameAndSex = {Name : string ; Sex : string} | |
type SurvivalStat = {PClass : string; Died : float; Survived :float} | |
let titanic = Squirrel.DataAcquisition.LoadCSV(@"C:\titanic.csv") | |
let classes = titanic.SplitOn("Pclass") | |
let result = new Squirrel.Table() | |
let pClasses = [|"1";"2";"3"|] | |
let persons = pClasses |> Array.map ( fun pClass -> | |
{ |
This file contains hidden or 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
//Stock symbols of companies for which you want to run this | |
string[] symbols = { "AAPL", "GOOG", "MSFT" }; | |
Dictionary<string, Table> stocks = new Dictionary<string, Table>(); | |
string template = @"http://real-chart.finance.yahoo.com/table.csv?s=[Symbol]&d=8&e=4&f=2014&g=d&a=0&b=2&c=1962&ignore=.csv"; | |
foreach (var symb in symbols) | |
{ | |
WebClient wc = new WebClient(); | |
wc.DownloadFile(template.Replace("[Symbol]", symb), "temp" + symb + ".csv"); | |
stocks.Add(symb, DataAcquisition.LoadCSV("temp" + symb + ".csv").Top(30)); | |
} |
This file contains hidden or 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"]); |
This file contains hidden or 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 iris = DataAcquisition.LoadCSV(@"iris.csv"); | |
StringBuilder builder = new StringBuilder(); | |
builder.AppendLine("<html>"); | |
builder.AppendLine("<h2>Range</h2>"); | |
builder.AppendLine(iris.Aggregate("Name", AggregationMethod.Range).ToHTMLTable()); | |
builder.AppendLine("<h2>Average</h2>"); | |
builder.AppendLine(iris.Aggregate("Name", AggregationMethod.Average).ToHTMLTable()); |
This file contains hidden or 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
//Problem : Locate average percentage of Tip paid by men and women from tips.csv | |
//Done in 3 lines of C# code using Squirrel.NET | |
//Loading the data to Squirrel.NET Table is easy | |
Table tips = DataAcquisition.LoadCSV(@"..\..\tips.csv"); | |
//Add a new column based on the formula | |
tips.AddColumn(columnName: "tip%", formula: "[tip]*100/[totbill]", decimalDigits: 3); |
This file contains hidden or 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
//Peter Norvig's Spell Check | |
Dictionary<string,int> NWords = new Dictionary<string,int>(); | |
public IEnumerable<string> Edits1(string word) | |
{ | |
char[] alphabet = {'a','b','c','d','e','f','g','h','j','k','l','m','n','o', | |
'p','q','r','s','t','u','v','w','x','y','z'}; | |
var splits = Enumerable.Range(1,word.Length).Select(i => new {First = new string(word.ToCharArray().Take(i).ToArray()), | |
Second = new string(word.ToCharArray().Skip(i).ToArray())}); | |
var deletes = splits.Where (split => !string.IsNullOrEmpty(split.Second)).Select (split => split.First + split.Second.Substring(1)); |
This file contains hidden or 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
public static class SequenceEx | |
{ | |
public static IEnumerable<T> StartWith<T>(params T[] seeds) | |
{ | |
return new List<T>(seeds).AsEnumerable(); | |
} | |
public static IEnumerable<T> ThenFollow<T>(this IEnumerable<T> thisSequence, | |
Func<T,T,T> rule) where T:IEquatable<T> | |
{ |
This file contains hidden or 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
public static class IntEx | |
{ | |
public static int Cube(this int number) | |
{ | |
return number * number * number; | |
} | |
public static int Square(this int number) | |
{ | |
return number * number; | |
} |
This file contains hidden or 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
SyntaxTree tree = SyntaxTree.ParseText(@"int fun(int x){ int y = 0; x++; return x+1;} | |
double funny(double x){ int s = 3; double t = 4; return x + s * t/2.13;}"); | |
List<MethodDeclarationSyntax> methods = tree.GetRoot() | |
.DescendantNodes() | |
.Where(d => d.Kind == SyntaxKind.MethodDeclaration) | |
.Cast<MethodDeclarationSyntax>() | |
.ToList(); | |
methods.Select(z => new { MethodName = z.Identifier.ValueText, |
This file contains hidden or 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
SyntaxTree tree = SyntaxTree.ParseText(@"int fun(int x){ int y = 10; x++; | |
if(x>20) x -= y; return x+1;} | |
double funny(double x){ int s = 3; double t = 4; | |
return x + s * t/2.13;}"); | |
List<MethodDeclarationSyntax> methods = tree.GetRoot() | |
.DescendantNodes() | |
.Where(d => d.Kind == SyntaxKind.MethodDeclaration) | |
.Cast<MethodDeclarationSyntax>().ToList(); |