Transformation to DataFrames#
Split-apply-combine
using DataFrames
Grouping a data frame#
groupby
x = DataFrame(id=[1, 2, 3, 4, 1, 2, 3, 4], id2=[1, 2, 1, 2, 1, 2, 1, 2], v=rand(8))
Row | id | id2 | v |
---|---|---|---|
Int64 | Int64 | Float64 | |
1 | 1 | 1 | 0.973202 |
2 | 2 | 2 | 0.046608 |
3 | 3 | 1 | 0.252007 |
4 | 4 | 2 | 0.628115 |
5 | 1 | 1 | 0.110051 |
6 | 2 | 2 | 0.544258 |
7 | 3 | 1 | 0.891864 |
8 | 4 | 2 | 0.24464 |
groupby(x, :id)
GroupedDataFrame with 4 groups based on key: id
Row | id | id2 | v |
---|---|---|---|
Int64 | Int64 | Float64 | |
1 | 1 | 1 | 0.973202 |
2 | 1 | 1 | 0.110051 |
⋮
Row | id | id2 | v |
---|---|---|---|
Int64 | Int64 | Float64 | |
1 | 4 | 2 | 0.628115 |
2 | 4 | 2 | 0.24464 |
groupby(x, [])
GroupedDataFrame with 1 group based on key:
Row | id | id2 | v |
---|---|---|---|
Int64 | Int64 | Float64 | |
1 | 1 | 1 | 0.973202 |
2 | 2 | 2 | 0.046608 |
3 | 3 | 1 | 0.252007 |
4 | 4 | 2 | 0.628115 |
5 | 1 | 1 | 0.110051 |
6 | 2 | 2 | 0.544258 |
7 | 3 | 1 | 0.891864 |
8 | 4 | 2 | 0.24464 |
gx2 = groupby(x, [:id, :id2])
GroupedDataFrame with 4 groups based on keys: id, id2
Row | id | id2 | v |
---|---|---|---|
Int64 | Int64 | Float64 | |
1 | 1 | 1 | 0.973202 |
2 | 1 | 1 | 0.110051 |
⋮
Row | id | id2 | v |
---|---|---|---|
Int64 | Int64 | Float64 | |
1 | 4 | 2 | 0.628115 |
2 | 4 | 2 | 0.24464 |
get the parent DataFrame
parent(gx2)
Row | id | id2 | v |
---|---|---|---|
Int64 | Int64 | Float64 | |
1 | 1 | 1 | 0.973202 |
2 | 2 | 2 | 0.046608 |
3 | 3 | 1 | 0.252007 |
4 | 4 | 2 | 0.628115 |
5 | 1 | 1 | 0.110051 |
6 | 2 | 2 | 0.544258 |
7 | 3 | 1 | 0.891864 |
8 | 4 | 2 | 0.24464 |
back to the DataFrame, but in a different order of rows than the original
vcat(gx2...)
Row | id | id2 | v |
---|---|---|---|
Int64 | Int64 | Float64 | |
1 | 1 | 1 | 0.973202 |
2 | 1 | 1 | 0.110051 |
3 | 2 | 2 | 0.046608 |
4 | 2 | 2 | 0.544258 |
5 | 3 | 1 | 0.252007 |
6 | 3 | 1 | 0.891864 |
7 | 4 | 2 | 0.628115 |
8 | 4 | 2 | 0.24464 |
the same as above
DataFrame(gx2)
Row | id | id2 | v |
---|---|---|---|
Int64 | Int64 | Float64 | |
1 | 1 | 1 | 0.973202 |
2 | 1 | 1 | 0.110051 |
3 | 2 | 2 | 0.046608 |
4 | 2 | 2 | 0.544258 |
5 | 3 | 1 | 0.252007 |
6 | 3 | 1 | 0.891864 |
7 | 4 | 2 | 0.628115 |
8 | 4 | 2 | 0.24464 |
drop grouping columns when creating a data frame
DataFrame(gx2, keepkeys=false)
Row | v |
---|---|
Float64 | |
1 | 0.973202 |
2 | 0.110051 |
3 | 0.046608 |
4 | 0.544258 |
5 | 0.252007 |
6 | 0.891864 |
7 | 0.628115 |
8 | 0.24464 |
vector of names of grouping variables
groupcols(gx2)
2-element Vector{Symbol}:
:id
:id2
and non-grouping variables
valuecols(gx2)
1-element Vector{Symbol}:
:v
group indices in parent(gx2)
groupindices(gx2)
8-element Vector{Union{Missing, Int64}}:
1
2
3
4
1
2
3
4
kgx2 = keys(gx2)
4-element DataFrames.GroupKeys{DataFrames.GroupedDataFrame{DataFrames.DataFrame}}:
GroupKey: (id = 1, id2 = 1)
GroupKey: (id = 2, id2 = 2)
GroupKey: (id = 3, id2 = 1)
GroupKey: (id = 4, id2 = 2)
You can index into a GroupedDataFrame
like to a vector or to a dictionary. The second form accepts GroupKey
, NamedTuple
or a Tuple
.
gx2
GroupedDataFrame with 4 groups based on keys: id, id2
Row | id | id2 | v |
---|---|---|---|
Int64 | Int64 | Float64 | |
1 | 1 | 1 | 0.973202 |
2 | 1 | 1 | 0.110051 |
⋮
Row | id | id2 | v |
---|---|---|---|
Int64 | Int64 | Float64 | |
1 | 4 | 2 | 0.628115 |
2 | 4 | 2 | 0.24464 |
k = keys(gx2)[1]
GroupKey: (id = 1, id2 = 1)
ntk = NamedTuple(k)
(id = 1, id2 = 1)
tk = Tuple(k)
(1, 1)
the operations below produce the same result and are proformant
gx2[1], gx2[k], gx2[ntk], gx2[tk]
(2×3 SubDataFrame
Row │ id id2 v
│ Int64 Int64 Float64
─────┼────────────────────────
1 │ 1 1 0.973202
2 │ 1 1 0.110051, 2×3 SubDataFrame
Row │ id id2 v
│ Int64 Int64 Float64
─────┼────────────────────────
1 │ 1 1 0.973202
2 │ 1 1 0.110051, 2×3 SubDataFrame
Row │ id id2 v
│ Int64 Int64 Float64
─────┼────────────────────────
1 │ 1 1 0.973202
2 │ 1 1 0.110051, 2×3 SubDataFrame
Row │ id id2 v
│ Int64 Int64 Float64
─────┼────────────────────────
1 │ 1 1 0.973202
2 │ 1 1 0.110051)
handling missing values
x = DataFrame(id=[missing, 5, 1, 3, missing], x=1:5)
Row | id | x |
---|---|---|
Int64? | Int64 | |
1 | missing | 1 |
2 | 5 | 2 |
3 | 1 | 3 |
4 | 3 | 4 |
5 | missing | 5 |
by default groups include missing values and their order is not guaranteed
groupby(x, :id)
GroupedDataFrame with 4 groups based on key: id
Row | id | x |
---|---|---|
Int64? | Int64 | |
1 | 1 | 3 |
⋮
Row | id | x |
---|---|---|
Int64? | Int64 | |
1 | missing | 1 |
2 | missing | 5 |
but we can change it; now they are sorted
groupby(x, :id, sort=true, skipmissing=true)
GroupedDataFrame with 3 groups based on key: id
Row | id | x |
---|---|---|
Int64? | Int64 | |
1 | 1 | 3 |
⋮
Row | id | x |
---|---|---|
Int64? | Int64 | |
1 | 5 | 2 |
and now they are in the order they appear in the source data frame
groupby(x, :id, sort=false)
GroupedDataFrame with 4 groups based on key: id
Row | id | x |
---|---|---|
Int64? | Int64 | |
1 | missing | 1 |
2 | missing | 5 |
⋮
Row | id | x |
---|---|---|
Int64? | Int64 | |
1 | 3 | 4 |
Performing transformations#
by group using combine, select, select!, transform, and transform!
using Statistics
using Chain
x = DataFrame(id=rand('a':'d', 100), v=rand(100))
Row | id | v |
---|---|---|
Char | Float64 | |
1 | c | 0.847674 |
2 | a | 0.894818 |
3 | d | 0.133443 |
4 | d | 0.744233 |
5 | d | 0.963738 |
6 | b | 0.74572 |
7 | c | 0.861151 |
8 | c | 0.699599 |
9 | a | 0.776682 |
10 | a | 0.383058 |
11 | c | 0.368769 |
12 | d | 0.712692 |
13 | b | 0.0873433 |
⋮ | ⋮ | ⋮ |
89 | d | 0.326667 |
90 | a | 0.92526 |
91 | b | 0.5512 |
92 | d | 0.538515 |
93 | a | 0.543957 |
94 | c | 0.404102 |
95 | c | 0.787083 |
96 | d | 0.931296 |
97 | a | 0.298847 |
98 | b | 0.445243 |
99 | c | 0.506366 |
100 | d | 0.264476 |
apply a function to each group of a data frame combine keeps as many rows as are returned from the function
@chain x begin
groupby(:id)
combine(:v => mean)
end
Row | id | v_mean |
---|---|---|
Char | Float64 | |
1 | c | 0.493781 |
2 | a | 0.507957 |
3 | d | 0.507968 |
4 | b | 0.443487 |
x.id2 = axes(x, 1)
Base.OneTo(100)
Select and transform keep as many rows as are in the source data frame and in correct order. Additionally, transform keeps all columns from the source.
@chain x begin
groupby(:id)
transform(:v => mean)
end
Row | id | v | id2 | v_mean |
---|---|---|---|---|
Char | Float64 | Int64 | Float64 | |
1 | c | 0.847674 | 1 | 0.493781 |
2 | a | 0.894818 | 2 | 0.507957 |
3 | d | 0.133443 | 3 | 0.507968 |
4 | d | 0.744233 | 4 | 0.507968 |
5 | d | 0.963738 | 5 | 0.507968 |
6 | b | 0.74572 | 6 | 0.443487 |
7 | c | 0.861151 | 7 | 0.493781 |
8 | c | 0.699599 | 8 | 0.493781 |
9 | a | 0.776682 | 9 | 0.507957 |
10 | a | 0.383058 | 10 | 0.507957 |
11 | c | 0.368769 | 11 | 0.493781 |
12 | d | 0.712692 | 12 | 0.507968 |
13 | b | 0.0873433 | 13 | 0.443487 |
⋮ | ⋮ | ⋮ | ⋮ | ⋮ |
89 | d | 0.326667 | 89 | 0.507968 |
90 | a | 0.92526 | 90 | 0.507957 |
91 | b | 0.5512 | 91 | 0.443487 |
92 | d | 0.538515 | 92 | 0.507968 |
93 | a | 0.543957 | 93 | 0.507957 |
94 | c | 0.404102 | 94 | 0.493781 |
95 | c | 0.787083 | 95 | 0.493781 |
96 | d | 0.931296 | 96 | 0.507968 |
97 | a | 0.298847 | 97 | 0.507957 |
98 | b | 0.445243 | 98 | 0.443487 |
99 | c | 0.506366 | 99 | 0.493781 |
100 | d | 0.264476 | 100 | 0.507968 |
note that combine reorders rows by group of GroupedDataFrame
@chain x begin
groupby(:id)
combine(:id2, :v => mean)
end
Row | id | id2 | v_mean |
---|---|---|---|
Char | Int64 | Float64 | |
1 | c | 1 | 0.493781 |
2 | c | 7 | 0.493781 |
3 | c | 8 | 0.493781 |
4 | c | 11 | 0.493781 |
5 | c | 14 | 0.493781 |
6 | c | 19 | 0.493781 |
7 | c | 24 | 0.493781 |
8 | c | 26 | 0.493781 |
9 | c | 27 | 0.493781 |
10 | c | 30 | 0.493781 |
11 | c | 37 | 0.493781 |
12 | c | 39 | 0.493781 |
13 | c | 47 | 0.493781 |
⋮ | ⋮ | ⋮ | ⋮ |
89 | b | 46 | 0.443487 |
90 | b | 65 | 0.443487 |
91 | b | 66 | 0.443487 |
92 | b | 69 | 0.443487 |
93 | b | 72 | 0.443487 |
94 | b | 75 | 0.443487 |
95 | b | 77 | 0.443487 |
96 | b | 78 | 0.443487 |
97 | b | 83 | 0.443487 |
98 | b | 85 | 0.443487 |
99 | b | 91 | 0.443487 |
100 | b | 98 | 0.443487 |
we give a custom name for the result column
@chain x begin
groupby(:id)
combine(:v => mean => :res)
end
Row | id | res |
---|---|---|
Char | Float64 | |
1 | c | 0.493781 |
2 | a | 0.507957 |
3 | d | 0.507968 |
4 | b | 0.443487 |
you can have multiple operations
@chain x begin
groupby(:id)
combine(:v => mean => :res1, :v => sum => :res2, nrow => :n)
end
Row | id | res1 | res2 | n |
---|---|---|---|---|
Char | Float64 | Float64 | Int64 | |
1 | c | 0.493781 | 14.8134 | 30 |
2 | a | 0.507957 | 12.6989 | 25 |
3 | d | 0.507968 | 12.6992 | 25 |
4 | b | 0.443487 | 8.86974 | 20 |
Additional notes:
select!
andtransform!
perform operations in-placeThe general syntax for transformation is
source_columns => function => target_column
if you pass multiple columns to a function they are treated as positional arguments
ByRow
andAsTable
work exactly like discussed for operations on data frames in 05_columns.ipynbyou can automatically groupby again the result of
combine
,select
etc. by passingungroup=false
keyword argument to themsimilarly
keepkeys
keyword argument allows you to drop grouping columns from the resulting data frame
It is also allowed to pass a function to all these functions (also - as a special case, as a first argument). In this case the return value can be a table. In particular it allows for an easy dropping of groups if you return an empty table from the function.
If you pass a function you can use a do
block syntax. In case of passing a function it gets a SubDataFrame
as its argument.
Here is an example:
combine(groupby(x, :id)) do sdf
n = nrow(sdf)
n < 25 ? DataFrame() : DataFrame(n=n) ## drop groups with low number of rows
end
Row | id | n |
---|---|---|
Char | Int64 | |
1 | c | 30 |
2 | a | 25 |
3 | d | 25 |
You can also produce multiple columns in a single operation:
df = DataFrame(id=[1, 1, 2, 2], val=[1, 2, 3, 4])
Row | id | val |
---|---|---|
Int64 | Int64 | |
1 | 1 | 1 |
2 | 1 | 2 |
3 | 2 | 3 |
4 | 2 | 4 |
@chain df begin
groupby(:id)
combine(:val => (x -> [x]) => AsTable)
end
Row | id | x1 | x2 |
---|---|---|---|
Int64 | Int64 | Int64 | |
1 | 1 | 1 | 2 |
2 | 2 | 3 | 4 |
@chain df begin
groupby(:id)
combine(:val => (x -> [x]) => [:c1, :c2])
end
Row | id | c1 | c2 |
---|---|---|---|
Int64 | Int64 | Int64 | |
1 | 1 | 1 | 2 |
2 | 2 | 3 | 4 |
It is easy to unnest the column into multiple columns,
df = DataFrame(a=[(p=1, q=2), (p=3, q=4)])
select(df, :a => AsTable)
Row | p | q |
---|---|---|
Int64 | Int64 | |
1 | 1 | 2 |
2 | 3 | 4 |
automatic column names generated
df = DataFrame(a=[[1, 2], [3, 4]])
select(df, :a => AsTable)
Row | x1 | x2 |
---|---|---|
Int64 | Int64 | |
1 | 1 | 2 |
2 | 3 | 4 |
custom column names generated
select(df, :a => [:C1, :C2])
Row | C1 | C2 |
---|---|---|
Int64 | Int64 | |
1 | 1 | 2 |
2 | 3 | 4 |
Finally, observe that one can conveniently apply multiple transformations using broadcasting:
df = DataFrame(id=repeat(1:10, 10), x1=1:100, x2=101:200)
Row | id | x1 | x2 |
---|---|---|---|
Int64 | Int64 | Int64 | |
1 | 1 | 1 | 101 |
2 | 2 | 2 | 102 |
3 | 3 | 3 | 103 |
4 | 4 | 4 | 104 |
5 | 5 | 5 | 105 |
6 | 6 | 6 | 106 |
7 | 7 | 7 | 107 |
8 | 8 | 8 | 108 |
9 | 9 | 9 | 109 |
10 | 10 | 10 | 110 |
11 | 1 | 11 | 111 |
12 | 2 | 12 | 112 |
13 | 3 | 13 | 113 |
⋮ | ⋮ | ⋮ | ⋮ |
89 | 9 | 89 | 189 |
90 | 10 | 90 | 190 |
91 | 1 | 91 | 191 |
92 | 2 | 92 | 192 |
93 | 3 | 93 | 193 |
94 | 4 | 94 | 194 |
95 | 5 | 95 | 195 |
96 | 6 | 96 | 196 |
97 | 7 | 97 | 197 |
98 | 8 | 98 | 198 |
99 | 9 | 99 | 199 |
100 | 10 | 100 | 200 |
@chain df begin
groupby(:id)
combine([:x1, :x2] .=> minimum)
end
Row | id | x1_minimum | x2_minimum |
---|---|---|---|
Int64 | Int64 | Int64 | |
1 | 1 | 1 | 101 |
2 | 2 | 2 | 102 |
3 | 3 | 3 | 103 |
4 | 4 | 4 | 104 |
5 | 5 | 5 | 105 |
6 | 6 | 6 | 106 |
7 | 7 | 7 | 107 |
8 | 8 | 8 | 108 |
9 | 9 | 9 | 109 |
10 | 10 | 10 | 110 |
@chain df begin
groupby(:id)
combine([:x1, :x2] .=> [minimum maximum])
end
Row | id | x1_minimum | x2_minimum | x1_maximum | x2_maximum |
---|---|---|---|---|---|
Int64 | Int64 | Int64 | Int64 | Int64 | |
1 | 1 | 1 | 101 | 91 | 191 |
2 | 2 | 2 | 102 | 92 | 192 |
3 | 3 | 3 | 103 | 93 | 193 |
4 | 4 | 4 | 104 | 94 | 194 |
5 | 5 | 5 | 105 | 95 | 195 |
6 | 6 | 6 | 106 | 96 | 196 |
7 | 7 | 7 | 107 | 97 | 197 |
8 | 8 | 8 | 108 | 98 | 198 |
9 | 9 | 9 | 109 | 99 | 199 |
10 | 10 | 10 | 110 | 100 | 200 |
Aggregation of a data frame using mapcols#
x = DataFrame(rand(10, 10), :auto)
Row | x1 | x2 | x3 | x4 | x5 | x6 | x7 | x8 | x9 | x10 |
---|---|---|---|---|---|---|---|---|---|---|
Float64 | Float64 | Float64 | Float64 | Float64 | Float64 | Float64 | Float64 | Float64 | Float64 | |
1 | 0.263127 | 0.877198 | 0.584535 | 0.899592 | 0.754093 | 0.288598 | 0.23089 | 0.276577 | 0.105592 | 0.976852 |
2 | 0.593438 | 0.113225 | 0.920428 | 0.823655 | 0.18551 | 0.264829 | 0.811713 | 0.150274 | 0.282963 | 0.288698 |
3 | 0.520668 | 0.277364 | 0.504678 | 0.389945 | 0.300603 | 0.568672 | 0.65554 | 0.818769 | 0.177598 | 0.666094 |
4 | 0.248962 | 0.667065 | 0.191287 | 0.394665 | 0.925936 | 0.0543978 | 0.287819 | 0.765772 | 0.680041 | 0.241801 |
5 | 0.461436 | 0.533172 | 0.364565 | 0.370468 | 0.366276 | 0.207401 | 0.0467888 | 0.469072 | 0.603109 | 0.983973 |
6 | 0.921979 | 0.0827353 | 0.917015 | 0.408304 | 0.15775 | 0.811074 | 0.509842 | 0.0597666 | 0.382358 | 0.307684 |
7 | 0.27564 | 0.944287 | 0.790453 | 0.942799 | 0.0492421 | 0.958079 | 0.26433 | 0.0949598 | 0.232186 | 0.87194 |
8 | 0.0962007 | 0.54146 | 0.370044 | 0.54388 | 0.851827 | 0.00907529 | 0.592196 | 0.0633686 | 0.163662 | 0.71178 |
9 | 0.83328 | 0.645829 | 0.625591 | 0.0473215 | 0.837015 | 0.327945 | 0.963545 | 0.344426 | 0.00757466 | 0.210299 |
10 | 0.232741 | 0.519151 | 0.180921 | 0.991015 | 0.896622 | 0.0761436 | 0.930661 | 0.904419 | 0.97458 | 0.930629 |
mapcols(mean, x)
Row | x1 | x2 | x3 | x4 | x5 | x6 | x7 | x8 | x9 | x10 |
---|---|---|---|---|---|---|---|---|---|---|
Float64 | Float64 | Float64 | Float64 | Float64 | Float64 | Float64 | Float64 | Float64 | Float64 | |
1 | 0.444747 | 0.520148 | 0.544952 | 0.581165 | 0.532487 | 0.356622 | 0.529333 | 0.39474 | 0.360966 | 0.618975 |
Mapping rows and columns using eachcol and eachrow#
map a function over each column and return a vector
map(mean, eachcol(x))
10-element Vector{Float64}:
0.44474714682317557
0.5201484905953546
0.5449515714761632
0.5811645813409286
0.5324872656441735
0.3566215707533047
0.5293326134324855
0.39474042721143554
0.3609663947412353
0.6189750547489952
an iteration returns a Pair with column name and values
foreach(c -> println(c[1], ": ", mean(c[2])), pairs(eachcol(x)))
x1: 0.44474714682317557
x2: 0.5201484905953546
x3: 0.5449515714761632
x4: 0.5811645813409286
x5: 0.5324872656441735
x6: 0.3566215707533047
x7: 0.5293326134324855
x8: 0.39474042721143554
x9: 0.3609663947412353
x10: 0.6189750547489952
now the returned value is DataFrameRow which works as a NamedTuple but is a view to a parent DataFrame
map(r -> r.x1 / r.x2, eachrow(x))
10-element Vector{Float64}:
0.29996299302778767
5.24124800610297
1.877198550350215
0.37321980323752285
0.865454240024211
11.143722651309448
0.29190334065555323
0.17766891870799123
1.2902488983315856
0.44831027267186824
it prints like a data frame, only the caption is different so that you know the type of the object
er = eachrow(x)
er.x1 ## you can access columns of a parent data frame directly
10-element Vector{Float64}:
0.26312679794452243
0.5934383993898801
0.5206675282484069
0.2489616895928357
0.4614360974663768
0.9219794376761827
0.2756404170403999
0.09620066883911571
0.8332796762631839
0.23274075577085218
it prints like a data frame, only the caption is different so that you know the type of the object
ec = eachcol(x)
Row | x1 | x2 | x3 | x4 | x5 | x6 | x7 | x8 | x9 | x10 |
---|---|---|---|---|---|---|---|---|---|---|
Float64 | Float64 | Float64 | Float64 | Float64 | Float64 | Float64 | Float64 | Float64 | Float64 | |
1 | 0.263127 | 0.877198 | 0.584535 | 0.899592 | 0.754093 | 0.288598 | 0.23089 | 0.276577 | 0.105592 | 0.976852 |
2 | 0.593438 | 0.113225 | 0.920428 | 0.823655 | 0.18551 | 0.264829 | 0.811713 | 0.150274 | 0.282963 | 0.288698 |
3 | 0.520668 | 0.277364 | 0.504678 | 0.389945 | 0.300603 | 0.568672 | 0.65554 | 0.818769 | 0.177598 | 0.666094 |
4 | 0.248962 | 0.667065 | 0.191287 | 0.394665 | 0.925936 | 0.0543978 | 0.287819 | 0.765772 | 0.680041 | 0.241801 |
5 | 0.461436 | 0.533172 | 0.364565 | 0.370468 | 0.366276 | 0.207401 | 0.0467888 | 0.469072 | 0.603109 | 0.983973 |
6 | 0.921979 | 0.0827353 | 0.917015 | 0.408304 | 0.15775 | 0.811074 | 0.509842 | 0.0597666 | 0.382358 | 0.307684 |
7 | 0.27564 | 0.944287 | 0.790453 | 0.942799 | 0.0492421 | 0.958079 | 0.26433 | 0.0949598 | 0.232186 | 0.87194 |
8 | 0.0962007 | 0.54146 | 0.370044 | 0.54388 | 0.851827 | 0.00907529 | 0.592196 | 0.0633686 | 0.163662 | 0.71178 |
9 | 0.83328 | 0.645829 | 0.625591 | 0.0473215 | 0.837015 | 0.327945 | 0.963545 | 0.344426 | 0.00757466 | 0.210299 |
10 | 0.232741 | 0.519151 | 0.180921 | 0.991015 | 0.896622 | 0.0761436 | 0.930661 | 0.904419 | 0.97458 | 0.930629 |
you can access columns of a parent data frame directly
ec.x1
10-element Vector{Float64}:
0.26312679794452243
0.5934383993898801
0.5206675282484069
0.2489616895928357
0.4614360974663768
0.9219794376761827
0.2756404170403999
0.09620066883911571
0.8332796762631839
0.23274075577085218
Transposing#
you can transpose a data frame using permutedims
:
df = DataFrame(reshape(1:12, 3, 4), :auto)
Row | x1 | x2 | x3 | x4 |
---|---|---|---|---|
Int64 | Int64 | Int64 | Int64 | |
1 | 1 | 4 | 7 | 10 |
2 | 2 | 5 | 8 | 11 |
3 | 3 | 6 | 9 | 12 |
df.names = ["a", "b", "c"]
3-element Vector{String}:
"a"
"b"
"c"
permutedims(df, :names)
Row | names | a | b | c |
---|---|---|---|---|
String | Int64 | Int64 | Int64 | |
1 | x1 | 1 | 2 | 3 |
2 | x2 | 4 | 5 | 6 |
3 | x3 | 7 | 8 | 9 |
4 | x4 | 10 | 11 | 12 |
This notebook was generated using Literate.jl.