# How write a dbf file

**URL:** <https://discourse.julialang.org/t/how-write-a-dbf-file/63930>\
**Category:** General Usage\
**Created:** [July 2, 2021, 12:00pm UTC](https://discourse.julialang.org/t/how-write-a-dbf-file/63930 "2021-07-02T12:00:25Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rafael\_Brus](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael_brus/32/23767_2.png) [@Rafael\_Brus](https://discourse.julialang.org/u/Rafael_Brus)\
**Post date:** [July 2, 2021, 12:00pm UTC](https://discourse.julialang.org/t/how-write-a-dbf-file/63930/1 "2021-07-02T12:00:25Z")

</div>

How write a dbf file from DataFrame?

---

<div class="post-metadata">

**Author:** ![visr](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/visr/32/17204_2.png) [@visr](https://discourse.julialang.org/u/visr)\
**Post date:** [July 2, 2021, 9:52pm UTC](https://discourse.julialang.org/t/how-write-a-dbf-file/63930/2 "2021-07-02T21:52:37Z")

</div>

There is [GitHub - JuliaData/DBFTables.jl: Functions for reading dbf files in Julia](https://github.com/JuliaData/DBFTables.jl), but it only supports reading at the moment, not writing.

So if you need to write DBF, your options, as far as I know, are, (1) add write support to DBFTables.jl, or (2) call into another non-julia code that can write DBF.

My main reason for working on DBFTables.jl is because DBF is used as a part of the geospatial shapefile format. GDAL knows how to write shapefiles, among many other formats. However we could make use of it, by putting some dummy geometries in a DataFrame and using [GeoDataFrames.jl](https://github.com/evetion/GeoDataFrames.jl) to write it to a shapefile. Then the other columns will end up in a DBF file.

```julia
using DataFrames, GeoDataFrames, ArchGDAL, DBFTables

point = ArchGDAL.createpoint(1.0, 2.0) # dummy geometry
df = DataFrame(A = 1:4, B = ["M", "F", "F", "M"], geom=point)

# this doesn't only write .shp, but also .dbf
GeoDataFrames.write("path/to/file.shp", df)

# now let's see if we can read the DBF with DBFTables back to DataFrames
dbf = DBFTables.Table("path/to/test.dbf")
DataFrame(dbf)

```

Which gives us the original DataFrame back!

```julia
4×2 DataFrame
 Row │ A B
     │ Int64 String
─────┼───────────────
   1 │ 1 M
   2 │ 2 F
   3 │ 3 F
   4 │ 4 M

```

---

<div class="post-metadata">

**Author:** ![joshday](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joshday/32/368_2.png) [@joshday](https://discourse.julialang.org/u/joshday)\
**Post date:** [June 2, 2023, 5:06pm UTC](https://discourse.julialang.org/t/how-write-a-dbf-file/63930/3 "2023-06-02T17:06:44Z")

</div>

Sorry for reviving such an old thread but I’d like to note that DBFTables now has `DBFTables.write` which works with any Tables.jl-compatible source.
