# How can I return the number of missings / uniques of a numerical type column?

**URL:** <https://discourse.julialang.org/t/how-can-i-return-the-number-of-missings-uniques-of-a-numerical-type-column/41726>\
**Category:** General Usage\
**Created:** [June 19, 2020, 1:25pm UTC](https://discourse.julialang.org/t/how-can-i-return-the-number-of-missings-uniques-of-a-numerical-type-column/41726 "2020-06-19T13:25:29Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Julia1](https://avatars.discourse-cdn.com/v4/letter/j/db5fbb/32.png) [@Julia1](https://discourse.julialang.org/u/Julia1)\
**Post date:** [June 19, 2020, 1:25pm UTC](https://discourse.julialang.org/t/how-can-i-return-the-number-of-missings-uniques-of-a-numerical-type-column/41726/1 "2020-06-19T13:25:29Z")

</div>

Hi how’s it going?

I’m trying to filter columns based on number of unique values and number of missings, and I just noticed that when calling the Describe() method on a DataFrame, it doesn’t work for numerical columns.

Whats the best solution to this?

```julia
df = DataFrame(:x=>[1.0,2.0,3.0],:y=>["1","2",missing])
describe(df)[!,[:variable,:nunique,:nmissing,:eltype]]

```

returns

 ![Screenshot from 2020-06-19 09-24-51](https://global.discourse-cdn.com/julialang/original/3X/d/0/d0688019946714fae5f404052948068b9729033f.png)

---

<div class="post-metadata">

**Author:** ![Henrique\_Becker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henrique_becker/32/15443_2.png) [@Henrique\_Becker](https://discourse.julialang.org/u/Henrique_Becker)\
**Post date:** [June 19, 2020, 1:44pm UTC](https://discourse.julialang.org/t/how-can-i-return-the-number-of-missings-uniques-of-a-numerical-type-column/41726/2 "2020-06-19T13:44:38Z")

</div>

I do not think that it is that it does not work on numeric columns, but instead that it displays nothing instead of zero when the column has no `missing` values, or when the column type does not allow for missing values. What do you get in the two cases below?

```julia
df = DataFrame(:x=>[1.0,2.0,missing],:y=>["1","2",missing])
describe(df)[!,[:variable,:nunique,:nmissing,:eltype]]

```

and

```julia
df = DataFrame(:x=>Union{Float64,Missing}[1.0,2.0,3.0],:y=>["1","2",missing])
describe(df)[!,[:variable,:nunique,:nmissing,:eltype]]

```

---

<div class="post-metadata">

**Author:** ![Julia1](https://avatars.discourse-cdn.com/v4/letter/j/db5fbb/32.png) [@Julia1](https://discourse.julialang.org/u/Julia1)\
**Post date:** [June 19, 2020, 1:54pm UTC](https://discourse.julialang.org/t/how-can-i-return-the-number-of-missings-uniques-of-a-numerical-type-column/41726/3 "2020-06-19T13:54:08Z")

</div>

> [@Henrique\_Becker](#):
>
> ```julia
> df = DataFrame(:x=>[1.0,2.0,missing],:y=>["1","2",missing])
> describe(df)[!,[:variable,:nunique,:nmissing,:eltype]]
> 
> ```

In both examples, the nunique column shows up empty, and the nmissing column shows up as 1 and 0, respectively. How come it doesn’t return the number of unique float values?

 ![Screenshot from 2020-06-19 09-54-27](https://global.discourse-cdn.com/julialang/original/3X/6/6/661ce4720310543243b483761bdf37392ab0be52.png)

---

<div class="post-metadata">

**Author:** ![Henrique\_Becker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henrique_becker/32/15443_2.png) [@Henrique\_Becker](https://discourse.julialang.org/u/Henrique_Becker)\
**Post date:** [June 19, 2020, 2:11pm UTC](https://discourse.julialang.org/t/how-can-i-return-the-number-of-missings-uniques-of-a-numerical-type-column/41726/4 "2020-06-19T14:11:24Z")

</div>

I am not sure of the rationale, but [it is clear that it is intended behavior](https://github.com/JuliaData/DataFrames.jl/blob/99b114344c3aa40de9b81bf40c2335aa74bb685c/src/abstractdataframe/abstractdataframe.jl#L646--L652). Probably because it leads to confusion when very similar values (often displayed with the same string) are considered different. If you want to get the number of unique values for a `<: Real` column you probably have to do it yourself with the epsilon most adequate for your case, instead of relying in code that is blind to orders of magnitude.

---

<div class="post-metadata">

**Author:** ![pdeffebach](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pdeffebach/32/10320_2.png) [@pdeffebach](https://discourse.julialang.org/u/pdeffebach)\
**Post date:** [June 19, 2020, 2:56pm UTC](https://discourse.julialang.org/t/how-can-i-return-the-number-of-missings-uniques-of-a-numerical-type-column/41726/5 "2020-06-19T14:56:17Z")

</div>

read the documentation for `describe` with `?describe`.

`nunique` is `nothing` for `<: Real` because in the vast majority of cases where columns are of type `<: Real` this is an expensive operation and we want `describe` to be fast. There is an issue for this [here](https://github.com/JuliaData/DataFrames.jl/issues/2269).

`nmissing` is `nothing` when the column doesn’t allow missing values because we want to distinguish “allows missing values but there are none of them” from “does not allow missing values”. This is covered in the documentation from `?describe`.

Why are you using `describe` for this task? Why not use `countmap`, `length(unique(x))`, or `count(ismissing, x)` to perform this operation?
