# How can I find the subset of dataframe that contain elements with Number datatype?

**URL:** <https://discourse.julialang.org/t/how-can-i-find-the-subset-of-dataframe-that-contain-elements-with-number-datatype/65388>\
**Category:** Performance\
**Tags:** dataframes\
**Created:** [July 27, 2021, 4:04pm UTC](https://discourse.julialang.org/t/how-can-i-find-the-subset-of-dataframe-that-contain-elements-with-number-datatype/65388 "2021-07-27T16:04:19Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Manu\_Francis](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/manu_francis/32/10010_2.png) [@Manu\_Francis](https://discourse.julialang.org/u/Manu_Francis)\
**Post date:** [July 27, 2021, 4:04pm UTC](https://discourse.julialang.org/t/how-can-i-find-the-subset-of-dataframe-that-contain-elements-with-number-datatype/65388/1 "2021-07-27T16:04:19Z")

</div>

Hi,  
I am trying to find subset of dataframe having elements with Number datatypes. But I couldn’t find any single function to find the subset. So I have implemented as

```julia
#df is the dataframe with columns having Number and string datatypes
nm = names(df)

  new_nm = String[]

  for (idx, ec) in enumerate(eachcol(df))

    if (eltype(ec) <:Number)

      push!(new_nm,nm[idx])

    end

  end
df_numeric_columns = df[!,new_nm]

```

Is there any better code or function to find out Number type columns?  
Thanks in Advance!,  
Manu

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [July 27, 2021, 4:15pm UTC](https://discourse.julialang.org/t/how-can-i-find-the-subset-of-dataframe-that-contain-elements-with-number-datatype/65388/2 "2021-07-27T16:15:54Z")

</div>

```julia
julia> using DataFrames

julia> df = DataFrame(col1 = rand(3), col2 = rand(1:10, 3), col3 = rand('a':'c', 3))
10×3 DataFrame
 Row │ a b c    
     │ Float64 Int64 Char 
─────┼───────────────────────
   1 │ 0.401624 2 b
   2 │ 0.94679 3 b
   3 │ 0.96397 9 b

julia> names(df, Number)
2-element Vector{String}:
 "col1"
 "col2"

```

---

<div class="post-metadata">

**Author:** ![Manu\_Francis](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/manu_francis/32/10010_2.png) [@Manu\_Francis](https://discourse.julialang.org/u/Manu_Francis)\
**Post date:** [July 27, 2021, 4:32pm UTC](https://discourse.julialang.org/t/how-can-i-find-the-subset-of-dataframe-that-contain-elements-with-number-datatype/65388/3 "2021-07-27T16:32:29Z")

</div>

> [@nilshg](#):
>
> `names(df, Number)`

Awesome … Thank you !!
