I have a problem in which the data is tabular, but one of the columns is the keys for the rest of the row. For example:
│ id │ x2 │ y2 │
│ String │ Int64 │ Int64 │
┼────────┼───────┼───────┤
│ a │ 1 │ 4 │
│ b │ 2 │ 5 │
│ k │ 3 │ 6 │
│ w │ 3 │ 5 │
│ c │ 4 │ 5 │
This data can be represented best as a Dict of Dicts. For example, the first row would be:
"a" => Dict(:x2 => 1 , :y2 => 4)
However, since the data is tabular, having the Tables.jl
will help in many situations. I was wondering if the Tables
’s interface can be extended to support the concept of keys
.
It should have an iterator similar to Dict:
for (key, rest_of_the_row) in dicttable
# iteration over kesys
end
The problems I can solve with this interface naturally:
# In `DictTable`, I specify the keys column in the first argument
# Suppose I want to merge `data` into `old_data` such that:
# - its `id`s are already in `old_data`, and
# - the output table includes `x1,x2`, and
# - a new column called `z` which for each row, its value is the `y2+y1`
data = DictTable( :id, :id => ["a","b","k","w","c"], :x2=>[1,2,3,3,4], :y2 => [4,5,6,5,5])
old_data = DictTable( :id, :id => ["c","b","a"], :x1=>[0,1,2], :y1 => [4,5,6])