# Get on GroupedDataFrame

**URL:** <https://discourse.julialang.org/t/get-on-groupeddataframe/36108>\
**Category:** Data\
**Created:** [March 17, 2020, 6:03pm UTC](https://discourse.julialang.org/t/get-on-groupeddataframe/36108 "2020-03-17T18:03:11Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Marc.Cox](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/marc.cox/32/7514_2.png) [@Marc.Cox](https://discourse.julialang.org/u/Marc.Cox)\
**Post date:** [March 17, 2020, 6:03pm UTC](https://discourse.julialang.org/t/get-on-groupeddataframe/36108/1 "2020-03-17T18:03:11Z")

</div>

Issue using the Base.get Get a group based on the values of the grouping columns example code  
here \>\> [Functions · DataFrames.jl](https://juliadata.github.io/DataFrames.jl/stable/lib/functions/#Base.get)

Base.get — Function.  
get(gd::GroupedDataFrame, key, default)  
Get a group based on the values of the grouping columns.

julia\>

```julia
df = DataFrame(a = repeat([:foo, :bar, :baz], outer=[2]),
                             b = repeat([2, 1], outer=[3]),
                             c = 1:6);

```

julia\> `gd = groupby(df, :a)`  
GroupedDataFrame with 3 groups based on key: a

julia\>` get(gd, (a=:bar,), nothing)`  
ERROR: MethodError: no method matching get(::GroupedDataFrame{DataFrame}, ::NamedTuple{(:a,),Tuple{Symbol}}, ::Nothing)  
Closest candidates are:  
get(::REPL.Terminals.TTYTerminal, ::Any, ::Any) at /buildworker/worker/package\_linux64/build/usr/share/julia/stdlib/v1.0/REPL/src/Terminals.jl:176  
get(::StatsModels.Schema, ::Any, ::Any) at /home/marc/.julia/packages/StatsModels/8N8nM/src/schema.jl:49  
get(::StatsModels.FullRank, ::Any, ::Any) at /home/marc/.julia/packages/StatsModels/8N8nM/src/schema.jl:253

**Julia Base v1.04**  
**(v1.0-EXP) pkg\> st**  
\*\* [a93c6f00] **DataFrames v0.20.2** \*\*

Any thoughts ,suggestions or work arounds appreciated.

---

<div class="post-metadata">

**Author:** ![bkamins](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bkamins/32/208538_2.png) [@bkamins](https://discourse.julialang.org/u/bkamins)\
**Post date:** [March 17, 2020, 6:32pm UTC](https://discourse.julialang.org/t/get-on-groupeddataframe/36108/2 "2020-03-17T18:32:27Z")

</div>

It works on v0.20.2, so probably you have an old version of DataFrames.jl

---

<div class="post-metadata">

**Author:** ![nalimilan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nalimilan/32/147_2.png) [@nalimilan](https://discourse.julialang.org/u/nalimilan)\
**Post date:** [March 17, 2020, 6:51pm UTC](https://discourse.julialang.org/t/get-on-groupeddataframe/36108/3 "2020-03-17T18:51:10Z")

</div>

Yet his post shows that he’s using 0.20.2. Can you confirm all of these results are from the same Julia session? Can you post the full copy/paste, and add the output of `methods(get)`?

(BTW, please use triple backticks around code blocks.)

---

<div class="post-metadata">

**Author:** ![bkamins](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bkamins/32/208538_2.png) [@bkamins](https://discourse.julialang.org/u/bkamins)\
**Post date:** [March 17, 2020, 7:37pm UTC](https://discourse.julialang.org/t/get-on-groupeddataframe/36108/4 "2020-03-17T19:37:26Z")

</div>

Ah - I have not noticed that (but I have checked on my machine that the code worked as expected, though on Julia 1.3.1)

---

<div class="post-metadata">

**Author:** ![Marc.Cox](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/marc.cox/32/7514_2.png) [@Marc.Cox](https://discourse.julialang.org/u/Marc.Cox)\
**Post date:** [March 17, 2020, 8:43pm UTC](https://discourse.julialang.org/t/get-on-groupeddataframe/36108/5 "2020-03-17T20:43:13Z")

</div>

Thank You for your help.

Seems I “hit the seam” between Julia Base and Dataframes,  
so is there a practical more general way that Dataframes development  
can stay independent/orthogonal of the Julia Base version ?  
Or at least automated testing / CBI / assertions that would catch bugs like this  
in the use case example code in the documentation…

Ok so the presently suggested solution is upgrade to New Julia version v1.3.1 ?  
Do we have more info handy about any other lower Julia versions that fixed the issue  
such as v1.2 , v1.1 etc. ?

I just did an image backup so I’m not opposed to New Julia version v1.3.1  
UNLESS v1.3.1 presents OTHER rude surprise “gotchas”  
like the upgrade from v0.7 to v1.0 where the Atom-Uber-Juno IDE plugin  
would NOT allow me to easily switch back to Julia v0.7  
^^ and failures to “just rollback” are quite unpleasant surprises,  
which I “forgave once” because by unspoken convention \<\< 1.0  
is considered BETA ergo subject to change.

Any pointers to known issues or advantages with Atom IDE upgrading from v1.04  
to new Julia version v1.3.1 ?

Also @bkamins I’m interested in alternative Dataframe soln **NOT using** `Base.get(gd, (a=:bar,)`  
for the following use case:

```julia
# df_Hinge_Segments:=6×3 DataFrame
# │ Row │ sym │ left │ right │
# │ │ Symbol │ Float64 │ Float64 │
# ├─────┼────────┼──────────┼─────────┤
# │ 1 │ w │ -3.34382 │ 2.68347 │
# │ 2 │ x │ -3.12436 │ -1.7407 │
# │ 3 │ x │ -1.7407 │ 1.71305 │
# │ 4 │ x │ 1.71305 │ 3.54989 │
# │ 5 │ y │ -11.3052 │ 13.0877 │
# │ 6 │ z │ -3.12796 │ 3.66479 │

```

NOTE DROP sym=:y , so Essentially Need a total of Three(3) Dicts that  
SPLIT integration\_limits:=Dict(:w=\>(-3.34382, 2.68347),:z=\>(-3.12796, 3.66479),:x=(-3.12436, 3.54989))  
because ( Count(:w)=1 times c(:x)=3 times c(:z)=1 ) = 3 combinations WITH 3 sym=:x LEFT,RIGHT ranges

btw I know I prefer understanding the “why” of things 👍 🕶 , so fyi this is part of an _Integration by Parts plan using MultivariateFunctions Piecewise\_Functions_

---

<div class="post-metadata">

**Author:** ![nalimilan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nalimilan/32/147_2.png) [@nalimilan](https://discourse.julialang.org/u/nalimilan)\
**Post date:** [March 17, 2020, 9:49pm UTC](https://discourse.julialang.org/t/get-on-groupeddataframe/36108/6 "2020-03-17T21:49:18Z")

</div>

I had also tried Julia 1.0.1 and it works there, so AFAICT that’s not a problem with the Julia version.

---

<div class="post-metadata">

**Author:** ![bkamins](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bkamins/32/208538_2.png) [@bkamins](https://discourse.julialang.org/u/bkamins)\
**Post date:** [March 17, 2020, 10:54pm UTC](https://discourse.julialang.org/t/get-on-groupeddataframe/36108/7 "2020-03-17T22:54:10Z")

</div>

Yes - we test everything against Julia 1.0 in CI and the tests of `get` pass.

---

<div class="post-metadata">

**Author:** ![bkamins](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bkamins/32/208538_2.png) [@bkamins](https://discourse.julialang.org/u/bkamins)\
**Post date:** [March 17, 2020, 10:55pm UTC](https://discourse.julialang.org/t/get-on-groupeddataframe/36108/8 "2020-03-17T22:55:56Z")

</div>

Regarding your question `get` is actually provided only for completeness when you expect that you might not find the key you are looking for. In your case writing:

```julia
gd[(:bar,)]

```

or

```julia
gd[(a=:bar,)]

```

should just work

---

<div class="post-metadata">

**Author:** ![Marc.Cox](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/marc.cox/32/7514_2.png) [@Marc.Cox](https://discourse.julialang.org/u/Marc.Cox)\
**Post date:** [March 17, 2020, 11:23pm UTC](https://discourse.julialang.org/t/get-on-groupeddataframe/36108/9 "2020-03-17T23:23:09Z")

</div>

> [@bkamins](#):
>
> gd[(:bar,)]

No luck so far with \>\>  
julia\> `gd[(a=:bar,)]`  
ERROR: MethodError: no method matching getindex(::GroupedDataFrame{DataFrame}, ::NamedTuple{(:a,),Tuple{Symbol}})  
Closest candidates are:  
getindex(::GroupedDataFrame, ::Integer) at /home/marc/.julia/packages/DataFrames/yH0f6/src/groupeddataframe/grouping.jl:164  
getindex(::GroupedDataFrame, ::AbstractArray) at /home/marc/.julia/packages/DataFrames/yH0f6/src/groupeddataframe/grouping.jl:168  
getindex(::GroupedDataFrame, ::Colon) at /home/marc/.julia/packages/DataFrames/yH0f6/src/groupeddataframe/grouping.jl:182

---

<div class="post-metadata">

**Author:** ![bkamins](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bkamins/32/208538_2.png) [@bkamins](https://discourse.julialang.org/u/bkamins)\
**Post date:** [March 18, 2020, 7:01am UTC](https://discourse.julialang.org/t/get-on-groupeddataframe/36108/10 "2020-03-18T07:01:13Z")

</div>

Can you please double check that you have DataFrames 0.20.2 installed. The " /home/marc/.julia/packages/DataFrames/yH0f6" directory name seems not to indicate 0.20.2 version of the DataFrames.jl (but some other version) as the last part of the path should be “S3ZFo”.

---

<div class="post-metadata">

**Author:** ![Marc.Cox](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/marc.cox/32/7514_2.png) [@Marc.Cox](https://discourse.julialang.org/u/Marc.Cox)\
**Post date:** [March 18, 2020, 8:51pm UTC](https://discourse.julialang.org/t/get-on-groupeddataframe/36108/11 "2020-03-18T20:51:25Z")

</div>

Thanks for your help.

OK so presently my plan is the following steps:

**rm --project DataFrames**

**rm --manifest DataFrames**

**add DataFrames**

ad let you know the results of **julia\>`gd[(a=:bar,)]`**

---

<div class="post-metadata">

**Author:** ![Marc.Cox](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/marc.cox/32/7514_2.png) [@Marc.Cox](https://discourse.julialang.org/u/Marc.Cox)\
**Post date:** [March 18, 2020, 11:43pm UTC](https://discourse.julialang.org/t/get-on-groupeddataframe/36108/12 "2020-03-18T23:43:25Z")

</div>

Thanks Bogumił @bkamins !

_ **Good catch on the version mismatch with installation folder !!** _

_Thanks for you help._ Now it Works Hurray !

_For future reference_ _I_ _took_ _the following steps:_

_ **rm --project DataFrames** _

_ **rm --manifest DataFrames** _

_ **add DataFrames** _

_## fyi_ _locked up and_ _needed a reboot at this point, which is odd for Linux …_

_## After reboot ,_ _when_ _restarted Atom_ _received_ _ **Info** _ _ **:** _ _ **about recompile ;** _ _and_ _also_ _received some strange Warnings and Errors Like so \>\>_

Press Enter to start Julia.

Starting Julia…

**[Info**  **: Recompiling stale cache file** /home/marc/.julia/compiled/v1.0/Atom/w9XOh.ji for Atom [c52e3926-4ff0-5f6e-af25-54175e0327b1]

.

.

[Info: Recompiling stale cache file /home/marc/.julia/compiled/v1.0/MultivariateFunctions/ig9dm.ji for MultivariateFunctions [54e48022-12d0-513b-b20d-e273c072c6db]

**┌ Warning: Error requiring Juno from PlotThemes:**

**│ LoadError: MethodError: no method matching hex(:**:UInt32, ::Int64, ::Bool)

│ You may have intended to import Base.hex

_│ Stacktrace:_

_ **## But Tests are working AOK, thanks again** _

_ **## But Tests are working AOK, thanks again** _

_**julia\> df = DataFrame(a = repeat([:foo, :bar, :baz], outer=[2]),**_

_**b = repeat([2, 1], outer=[3]),**_

_**c = 1:6);**_

_**julia\> gd = groupby(df, :a)**_

_GroupedDataFrame with 3 groups based on key: a_

_First Group (2 rows): a = :foo_

_│ Row │ a │ b │ c │_

_│ │ Symbol │ Int64 │ Int64 │_

_├─────┼────────┼───────┼───────┤_

_│ 1 │ foo │ 2 │ 1 │_

_│ 2 │ foo │ 1 │ 4 │_

_⋮_

_Last Group (2 rows): a = :baz_

_│ Row │ a │ b │ c │_

_│ │ Symbol │ Int64 │ Int64 │_

_├─────┼────────┼───────┼───────┤_

_│ 1 │ baz │ 2 │ 3 │_

_│ 2 │ baz │ 1 │ 6 │_

_**julia\> get(gd, (a=:bar,), nothing)**_

_2×3 SubDataFrame_

_│ Row │ a │ b │ c │_

_│ │ Symbol │ Int64 │ Int64 │_

_├─────┼────────┼───────┼───────┤_

_│ 1 │ bar │ 1 │ 2 │_

_│ 2 │ bar │ 2 │ 5 │_

_**julia\> gd[(a=:bar,)]**_

_2×3 SubDataFrame_

_│ Row │ a │ b │ c │_

_│ │ Symbol │ Int64 │ Int64 │_

_├─────┼────────┼───────┼───────┤_

_│ 1 │ bar │ 1 │ 2 │_

_│ 2 │ bar │ 2 │ 5 │_

_ **Good catch on the version mismatch with installation folder !!** _

_ **Marking above as solution per** _ _ **Tests are** _ _ **now** _ _ **working AOK,** _

_ **Thanks again !!** _
