Count unique in a Deedle Series

て烟熏妆下的殇ゞ 提交于 2020-01-03 17:29:11

问题


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)]

回答1:


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


来源:https://stackoverflow.com/questions/56164089/count-unique-in-a-deedle-series

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!