This repository has been archived by the owner on Jun 17, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CSV.fs
63 lines (52 loc) · 1.42 KB
/
CSV.fs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
module CSV
open FSharp.Data
open Deedle
open XPlot.GoogleCharts
type TitanicData = CsvProvider<"data/csv/titanic.csv">
let data = TitanicData.Load "data/csv/titanic.csv"
let count matching data =
let all = data |> Seq.length
let matching =
data
|> Seq.where matching
|> Seq.length
float matching / float all
let survivalByAgeClass =
data.Rows
|> Seq.groupBy (fun p ->
p.Pclass,
((p.Age / 10.0)
|> floor
|> int)
* 10)
|> Seq.map (fun (groups, data) -> groups, data |> count (fun p -> p.Survived))
|> Seq.groupBy (fst >> fst)
|> Seq.sortBy fst
|> Seq.map (fun (age, data) ->
data
|> Seq.map (fun (t, avg) -> snd t, avg)
|> Seq.sort)
|> Chart.Line
let survivedByClass =
data.Rows
|> Seq.groupBy (fun p -> p.Pclass, p.Survived)
|> Seq.map (fun (group, data) ->
let (clas, survived) = group
string clas,
(if survived then "Survived" else "Died"), data |> Seq.length)
|> Chart.Sankey
let age =
data.Rows
|> Seq.map (fun p -> p.Name.Replace("\"",""), p.Age)
|> Chart.Histogram
|> Chart.WithLabel "Age"
let ageToFare =
data.Rows
|> Seq.map (fun p -> p.Fare, p.Age)
|> Chart.Scatter
let passangersInClasses =
data.Rows
|> Seq.countBy (fun p -> p.Pclass)
|> Seq.sort
|> Chart.Table
|> Chart.WithLabels ["Class";"Passanger Count"]