# Create a data frame with several self-defined types in Julia

**URL:** https://discourse.julialang.org/t/create-a-data-frame-with-several-self-defined-types-in-julia/23345
**Category:** General Usage
**Created:** [April 20, 2019, 2:06pm UTC](https://discourse.julialang.org/t/create-a-data-frame-with-several-self-defined-types-in-julia/23345 "2019-04-20T14:06:16Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![bsnyh](https://avatars.discourse-cdn.com/v4/letter/b/ce7236/32.png) [@bsnyh](https://discourse.julialang.org/u/bsnyh)
#### Post date: [April 20, 2019, 2:06pm UTC](https://discourse.julialang.org/t/create-a-data-frame-with-several-self-defined-types-in-julia/23345/1 "2019-04-20T14:06:16Z")

</div>

I have a self-defined mutable struct as the following.

`@enum Fruits Apple Pear Orange`

I also have a .csv file, of which the second column is called fruitsCategories, which lists the categories of all the fruits. Then, I need to read this csv file. Now, the second column is of type String. But what I need is this self-defined enumerate type Fruits. So how to accomplish this?

Note: I create this .csv file. So I can add one more column, which is called integerCategory. Then combining with the enumerate type, can get the corresponding category.  
But is there any other way then? Because the integerCategory is not really necessary…

EDIT: sorry if I did not explain this clearly. When this .csv file is created, I’m using `CSV.write(fln, df)` to write a data frame `df` to the file with name `fln`. So I think it would be great if I somehow can let Julia know that the column fruitsCategories of of a self-defined type, not of type String.

---

<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: [April 20, 2019, 2:09pm UTC](https://discourse.julialang.org/t/create-a-data-frame-with-several-self-defined-types-in-julia/23345/2 "2019-04-20T14:09:59Z")

</div>

Do you think you might be better off using a `CategoricalArray`?

---

<div class="post-metadata">

### Author: ![bsnyh](https://avatars.discourse-cdn.com/v4/letter/b/ce7236/32.png) [@bsnyh](https://discourse.julialang.org/u/bsnyh)
#### Post date: [April 20, 2019, 2:13pm UTC](https://discourse.julialang.org/t/create-a-data-frame-with-several-self-defined-types-in-julia/23345/3 "2019-04-20T14:13:15Z")

</div>

Thank you for quick responses. So in stead of enumerate type, a `CategoricalArray` is better? need to dig more.

---

<div class="post-metadata">

### Author: ![bsnyh](https://avatars.discourse-cdn.com/v4/letter/b/ce7236/32.png) [@bsnyh](https://discourse.julialang.org/u/bsnyh)
#### Post date: [April 20, 2019, 2:32pm UTC](https://discourse.julialang.org/t/create-a-data-frame-with-several-self-defined-types-in-julia/23345/4 "2019-04-20T14:32:49Z")

</div>

I found this link: [Is there a way that I can attach string labels to integer values in CategoricalArrays?](https://discourse.julialang.org/t/is-there-a-way-that-i-can-attach-string-labels-to-integer-values-in-categoricalarrays/8970)  
Is there anything else that can be done using categoricalarray besides

```julia
julia> a = categorical([1,2,1,3])

julia> recode(a, 1=>"a", 2=>"b", 3=>"c")

```

Thank you.

---

<div class="post-metadata">

### Author: ![bsnyh](https://avatars.discourse-cdn.com/v4/letter/b/ce7236/32.png) [@bsnyh](https://discourse.julialang.org/u/bsnyh)
#### Post date: [April 20, 2019, 2:47pm UTC](https://discourse.julialang.org/t/create-a-data-frame-with-several-self-defined-types-in-julia/23345/5 "2019-04-20T14:47:12Z")

</div>

what is the main difference between enumerate type and categoricalarray in terms of usage then?
