Get first 10 rows of a Deedle Frame in F#

48 Views Asked by At

I'm encountering an issue while attempting to retrieve the first 10 rows of a DataFrame in F#. Can anyone provide guidance or solutions? Thank you.

//Select the first 10 rows of the DataFrame
let rows = df.Head(10)
//display the rows
printfn "%A" rows

error: typecheck error The type 'Unit' does not define the field, constructor or member 'Head'.

I am trying to display the first 10 rows of a dataframe in F# and I am getting error.

1

There are 1 best solutions below

1
Brian Berns On

In your example, df is not a data frame. We'd have to see more of your code to tell you why.

Assuming your row keys are sequential integers, you can print the first 10 rows of a data frame like this:

open Deedle

let df =
    Seq.init 100 (fun x -> x, "2x", 2 * x)
        |> Frame.ofValues

//Select the first 10 rows of the DataFrame
let rows = df.Rows[0..9]
//display the rows
rows.Print()

Output is:

      2x
0  -> 0
1  -> 2
2  -> 4
3  -> 6
4  -> 8
5  -> 10
6  -> 12
7  -> 14
8  -> 16
9  -> 18

Related Questions in F#