Skip to content

Commit 489b320

Browse files
authored
Update the "Usage" example in the README (#36)
* update readme usage example * change part of example
1 parent e5d4c37 commit 489b320

File tree

1 file changed

+23
-20
lines changed

1 file changed

+23
-20
lines changed

README.md

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,28 +13,31 @@ Read xBase / dBASE III+ [.dbf](https://en.wikipedia.org/wiki/.dbf) files in Juli
1313
## Usage
1414

1515
```julia
16-
using DBFTables
17-
dbf = DBFTables.Table("test.dbf")
18-
19-
# whole columns can be retrieved by their name
20-
# note that this creates a copy, so instead of repeated `dbf.field` calls,
21-
# it is faster to once do `field = dbf.field` and then use `field` instead
22-
dbf.INTEGER # => Union{Missing, Int64}[100, 101, 102, 0, 2222222222, 4444444444, missing]
23-
24-
# example function that iterates over the rows and uses two columns
25-
function sumif(dbf)
26-
total = 0.0
27-
for row in dbf
28-
if row.BOOLEAN && !ismissing(row.NUMERIC)
29-
value += row.NUMERIC
30-
end
31-
end
32-
return total
16+
using DBFTables, DataFrames
17+
18+
df = DataFrame(
19+
x = 1:5,
20+
y = rand(Bool, 5),
21+
z = ["a", "b", "c", "d", "e"]
22+
)
23+
24+
# Write any Tables.jl source to a .dbf file
25+
path = tempname()
26+
DBFTables.write(path, df)
27+
28+
# Read the data back in from the .dbf file
29+
dbf = DBFTables.Table(path)
30+
31+
# Retrieve columns by their name
32+
dbf.x
33+
34+
# Iterate over the rows (values can be accessed by column name)
35+
for row in dbf
36+
@info (row.x, row.y, row.z)
3337
end
3438

35-
# for other functionality, convert to other Tables such as DataFrame
36-
using DataFrames
37-
df = DataFrame(dbf)
39+
# Pass the DBFTables.Table to any Tables.jl sink
40+
df2 = DataFrame(dbf)
3841
```
3942

4043
## Format description resources

0 commit comments

Comments
 (0)