Code Monkey home page Code Monkey logo

Comments (2)

ingted avatar ingted commented on July 22, 2024

The result:

val data: string = "A;B
a;1
b;2
b;2
c;3"
val bytes: byte array =
  [|65uy; 59uy; 66uy; 10uy; 97uy; 59uy; 49uy; 10uy; 98uy; 59uy; 50uy; 10uy;
    98uy; 59uy; 50uy; 10uy; 99uy; 59uy; 51uy|]
val stream: IO.MemoryStream
val df: Frame<int,string> =
  
     A B 
0 -> a 1 
1 -> b 2 
2 -> b 2 
3 -> c 3 

4 rows x 2 columns
0 missing values
val it: Frame<int,string> =
  
     A B 
0 -> a 1 
1 -> b 2 
3 -> c 3 

3 rows x 2 columns
0 missing values

from deedle.

ingted avatar ingted commented on July 22, 2024
module Frame = 
    let inline distinctFrame (keys: 'C seq) (distColId:'C) (frame: Frame<'R, 'C>) =

        let idxSource = 
            frame
            |> Frame.mapRows (fun (i:'R) r ->
                i, keys |> Seq.map r.TryGet |> Seq.toArray
            )
            |> fun s -> s.Values

        let idx = 
            idxSource
            |> Seq.groupBy (fun (_, g) -> g)
            |> Seq.map (fun g -> 
                let (idx, _) = snd g |> Seq.item 0
                idx
                )
            |> Seq.distinct
            |> fun s -> Frame([distColId], [Series(s, s)])//"____distinctIdx____"

        let fmj = frame.Join(idx, kind=JoinKind.Inner)
        fmj.Columns.[fmj.ColumnKeys |> Seq.filter (fun v -> v <> distColId)]

    let inline orderBy (mappingOrderKeys: ObjectSeries<'C> -> int) (distColId:'C) (frame: Frame<'R, 'C>) =        
        let idxSource = 
            frame
            |> Frame.mapRows (fun (i:'R) r ->
                mappingOrderKeys r
            )
            |> fun s -> Frame([distColId], [s])//"____distinctIdx____"
        
        frame.Join(idxSource, kind=JoinKind.Inner)
        |> Frame.sortRows distColId


    let inline orderByCols (keys: 'C seq) (distColId:'C) (frame: Frame<'R, 'C>) =
        let colValues = 
            frame
            |> Frame.mapRowValues (fun row ->
                let values = 
                    keys
                    |> Seq.map (fun k ->
                        row.[k]
                    )
                    |> Seq.toArray
                values |> Array.map (fun v -> v :?> IComparable)
            )

        let orderKeys =
            colValues.Values
            |> Seq.distinct
            |> Seq.sort
            |> Seq.mapi (fun i v -> v, i)
            |> Map
           
        let ordered =
            colValues
            |> Series.map (fun c v -> orderKeys.[v])

        let appendCol =
            Frame.ofColumns [distColId, ordered]


        frame.Join(appendCol, kind=JoinKind.Inner)
        |> Frame.sortRows distColId

orderBy & orderByCols functionality

from deedle.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.