4 people like it.

BigData Analysis using Deedle and FSharp.Charting

Tomas has released their F# data analysis library called Deedle, I just got around to playing with it. It looks really cool!

 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: 
#load @"J:\VS2013 Projects\...\FsLab.fsx"

open Deedle
open FSharp.Charting

(* The raw data is from: http://www.ed.ac.uk/schools-departments/geosciences/weather-station/download-weather-data *)
let last31 = Frame.ReadCsv("J:/BigData/JCMB_last31days.csv")

// To find how many days that the surface temperature is low than 2 Celsius at 2pm.
let resultDays = 
    last31
    // extract time and temperature columns
    |> Frame.getCols["time"; "temperature"]
    // filter out the time and temperature of interests
    |> Frame.filterRowValues(fun row -> row?time = 1400.0 && row?temperature < 2.0)
    // count the results
    |> Frame.countRows

// In the past 31 days, only 2 days at 2pm the temperature was lower than 2.0 Celsius.
// val resultDays : int = 2

// Time series (at 2pm)
let twoPmCol = 
    last31
    |> Frame.getSeries("time")
    |> Series.filterValues(fun s -> s = 1400.0)

Chart.Pie(twoPmCol)

// Temperatures series(higher than 12.85 Cel)
let higherTemp= 
    last31
    |> Frame.getSeries("temperature")
    |> Series.filterValues(fun c -> c > 12.85)

Chart.Pie(higherTemp)

let newFrame = Frame(["Time"; "HighTemperature"], [twoPmCol; higherTemp])

//Combine chart
Chart.Combine[
                Chart.Line(newFrame?Time |> Series.observations)
                Chart.Line(newFrame?HighTemperature |> Series.observations)
             ]

// Sample to plot using Chart.Bar
let sample = 
    last31
        // extract time and temperature columns
        |> Frame.getCols["time"; "temperature"]
        // filter out the time and temperature of interests
        |> Frame.filterRowValues(fun row -> row?time = 1400.0 && row?temperature > 0.0)

Chart.Bar((sample?temperature) |> Series.observations)
namespace Microsoft.FSharp
val last31 : obj

Full name: Script.last31
val resultDays : obj

Full name: Script.resultDays
val twoPmCol : obj

Full name: Script.twoPmCol
val higherTemp : obj

Full name: Script.higherTemp
val newFrame : obj

Full name: Script.newFrame
val sample : obj

Full name: Script.sample
Raw view Test code New version

More information

Link:http://fssnip.net/kZ
Posted:11 years ago
Author:Joel Huang
Tags: big data , data science , deedle , fsharp.charting