# Column types in DataFrames

**URL:** https://discourse.julialang.org/t/column-types-in-dataframes/108532
**Category:** New to Julia
**Tags:** dataframes
**Created:** [January 8, 2024, 6:55pm UTC](https://discourse.julialang.org/t/column-types-in-dataframes/108532 "2024-01-08T18:55:49Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![vsoler](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vsoler/32/30667_2.png) [@vsoler](https://discourse.julialang.org/u/vsoler)
#### Post date: [January 8, 2024, 6:55pm UTC](https://discourse.julialang.org/t/column-types-in-dataframes/108532/1 "2024-01-08T18:55:49Z")

</div>

I have a big DataFrame named `df`.

I want to create, from it, another DataFrame with 2 columns: the first column should contain the column names of `df`. The second column should contain its column types.

I have tried this:

```julia
using DataFrames
df = DataFrame(a=Int[], b=String[], c=Union{Missing, Int})

function get_column_info(df::DataFrame)
     col_names = names(df)
     col_types = eltype.(eachcol(df))
     return DataFrame(Column_Names = col_names, Column_Types = col_types)
end

new_df = get_column_info(df)

```

And I get this:

 ![image](https://global.discourse-cdn.com/julialang/original/3X/7/a/7a57c4e9336c232af725d5aeaea58841d774cf9b.png)

I expected to see Union{Missing, Int64} for column “c”. That’s not what I got.

So I tried something different:

```julia
function get_column_info(df::DataFrame)
    col_names = names(df)
    col_types = [typeof(col) for col in eachcol(df)]
    return DataFrame(Column_Names = col_names, Column_Types = col_types)
end

new_df = get_column_info(df)

```

This time what I got is:

 ![image](https://global.discourse-cdn.com/julialang/original/3X/d/7/d766861898fdc0fe5d68264a56b532877223edfb.png)

It is not what I expected.

Does anybody have any suggestions as to how to proceed?

Thank you

---

<div class="post-metadata">

### Author: ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)
#### Post date: [January 8, 2024, 7:00pm UTC](https://discourse.julialang.org/t/column-types-in-dataframes/108532/2 "2024-01-08T19:00:35Z")

</div>

> [@vsoler](#):
>
> `c=Union{Missing, Int}`

For consistency with the other dataframe entries, I think this should be:  
`c=Union{Missing, Int}[]`

---

<div class="post-metadata">

### Author: ![vsoler](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vsoler/32/30667_2.png) [@vsoler](https://discourse.julialang.org/u/vsoler)
#### Post date: [January 8, 2024, 7:03pm UTC](https://discourse.julialang.org/t/column-types-in-dataframes/108532/3 "2024-01-08T19:03:30Z")

</div>

I think you are right.

The problem seems to be solved, thank you.

---

<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: [January 8, 2024, 7:14pm UTC](https://discourse.julialang.org/t/column-types-in-dataframes/108532/4 "2024-01-08T19:14:09Z")

</div>

You might also like `describe(df)` and in particular `describe(df, :eltype)`
