# Writing a Dict to a CSV

**URL:** <https://discourse.julialang.org/t/writing-a-dict-to-a-csv/60769>\
**Category:** New to Julia\
**Created:** [May 8, 2021, 9:19am UTC](https://discourse.julialang.org/t/writing-a-dict-to-a-csv/60769 "2021-05-08T09:19:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![SpinolaHours](https://avatars.discourse-cdn.com/v4/letter/s/a3d4f5/32.png) [@SpinolaHours](https://discourse.julialang.org/u/SpinolaHours)\
**Post date:** [May 8, 2021, 9:19am UTC](https://discourse.julialang.org/t/writing-a-dict-to-a-csv/60769/1 "2021-05-08T09:19:02Z")

</div>

Hi there,

I’d like to write a dictionary to a csv such that:

d1 = Dict(:a=\>1, :b=\>2, :c=\>3)

writes to CSV as:

a b c  
1 2 3

additionally I then want to append another dictionary as follows:

d2 = Dict(:a=\>4, :b=\>5, :c=\>6)

CSV.write(“test.csv”, d2, append=true)

CSV would now read:

a b c  
1 2 3  
4 5 6

Struggling to find a way to acheive this. Any help would be appreciated. Thanks!

---

<div class="post-metadata">

**Author:** ![danielw2904](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/danielw2904/32/10890_2.png) [@danielw2904](https://discourse.julialang.org/u/danielw2904)\
**Post date:** [May 8, 2021, 10:04am UTC](https://discourse.julialang.org/t/writing-a-dict-to-a-csv/60769/2 "2021-05-08T10:04:01Z")

</div>

There might be a smarter way but I usually create a DataFrame from the dict and then write that to CSV.

---

<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:** [May 8, 2021, 11:49am UTC](https://discourse.julialang.org/t/writing-a-dict-to-a-csv/60769/3 "2021-05-08T11:49:47Z")

</div>

The simplest, dependency-free approach is probably to just create a `NamedTuple`

```julia
julia> NamedTuple(d1)
(a = 1, b = 2, c = 3)

```

Which satisfies the `Tables.Table` interface and therefore can be written to CSV.
