From 489b320ea8794eee57b7111db335d34e383e2019 Mon Sep 17 00:00:00 2001 From: Josh Day Date: Wed, 19 Jun 2024 20:05:41 -0400 Subject: [PATCH] Update the "Usage" example in the README (#36) * update readme usage example * change part of example --- README.md | 43 +++++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 6116c75..6c22df3 100644 --- a/README.md +++ b/README.md @@ -13,28 +13,31 @@ Read xBase / dBASE III+ [.dbf](https://en.wikipedia.org/wiki/.dbf) files in Juli ## Usage ```julia -using DBFTables -dbf = DBFTables.Table("test.dbf") - -# whole columns can be retrieved by their name -# note that this creates a copy, so instead of repeated `dbf.field` calls, -# it is faster to once do `field = dbf.field` and then use `field` instead -dbf.INTEGER # => Union{Missing, Int64}[100, 101, 102, 0, 2222222222, 4444444444, missing] - -# example function that iterates over the rows and uses two columns -function sumif(dbf) - total = 0.0 - for row in dbf - if row.BOOLEAN && !ismissing(row.NUMERIC) - value += row.NUMERIC - end - end - return total +using DBFTables, DataFrames + +df = DataFrame( + x = 1:5, + y = rand(Bool, 5), + z = ["a", "b", "c", "d", "e"] +) + +# Write any Tables.jl source to a .dbf file +path = tempname() +DBFTables.write(path, df) + +# Read the data back in from the .dbf file +dbf = DBFTables.Table(path) + +# Retrieve columns by their name +dbf.x + +# Iterate over the rows (values can be accessed by column name) +for row in dbf + @info (row.x, row.y, row.z) end -# for other functionality, convert to other Tables such as DataFrame -using DataFrames -df = DataFrame(dbf) +# Pass the DBFTables.Table to any Tables.jl sink +df2 = DataFrame(dbf) ``` ## Format description resources