eachindex
used on a GroupedDataFrame, returns a GroupKey, such as GroupKey: (site = 'b',)
.
When using the indices to create figure layouts in Makie or other plotting packages, (Axis(fig[i, 1]
), one should explicitly ask for IndexLinear from eachindex
.
demo code
using DataFrames
"""
gdfindices()
Demonstrate behavior of `eachindex` with GroupedDataFrame.
"""
function gdfindices()
df = DataFrame(site = rand('a':'e', 1000), yield = rand(1:100, 1000))
grpdf = groupby(df, :site)
println(" Keys:")
show(stdout, "text/plain", keys(grpdf))
naiveindx = eachindex(grpdf)
println("\n\n eachindex(grpdf):")
show(stdout, "text/plain", naiveindx)
indx = eachindex(IndexLinear(), grpdf)
println("\n\n eachindex, IndexLinear:")
show(stdout, "text/plain", indx)
end
julia> gdfindices()
Keys:
5-element DataFrames.GroupKeys{DataFrames.GroupedDataFrame{DataFrames.DataFrame}}:
GroupKey: (site = 'b',)
GroupKey: (site = 'c',)
GroupKey: (site = 'd',)
GroupKey: (site = 'a',)
GroupKey: (site = 'e',)
eachindex(grpdf):
5-element DataFrames.GroupKeys{DataFrames.GroupedDataFrame{DataFrames.DataFrame}}:
GroupKey: (site = 'b',)
GroupKey: (site = 'c',)
GroupKey: (site = 'd',)
GroupKey: (site = 'a',)
GroupKey: (site = 'e',)
eachindex, IndexLinear:
Base.OneTo(5)