4

I want to have an overview of a Series in my dataframe, something like pandas' unique values counting. I don't know if there's a built-in function for that.

So far i've done a function to just get the numbers of different features. I could manage to do the job, my question is only about a built-in function.

let unique (s:Deedle.Series<'a,'a>) = 
    s.Values
    |>Seq.distinct
    |>Seq.length

I want a result like :

[("value1",5);("value2",8)]
Youness Kafia
  • 173
  • 1
  • 5

1 Answers1

4

You can use the groupInto function - this lets you group values of the series, so you can group the data using the actual value as the key and then aggregate each group into a single value by counting the total number of items in the group:

let unique s = 
  s |> Series.groupInto (fun _ v -> v) (fun _ g -> Stats.count g)

Series.ofValues [ 1;2;1;2;3 ] |> unique
Tomas Petricek
  • 240,744
  • 19
  • 378
  • 553