# Groupby / reshaping dataframe with unique values

**URL:** <https://discourse.julialang.org/t/groupby-reshaping-dataframe-with-unique-values/51149>\
**Category:** Data\
**Tags:** data, dataframes\
**Created:** [December 2, 2020, 8:54pm UTC](https://discourse.julialang.org/t/groupby-reshaping-dataframe-with-unique-values/51149 "2020-12-02T20:54:30Z")\
**Posts on this page:** 1\
**Showing post:** 18

<div class="post-metadata">

**Author:** ![rocco\_sprmnt21](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rocco_sprmnt21/32/20127_2.png) [@rocco\_sprmnt21](https://discourse.julialang.org/u/rocco_sprmnt21)\
**Post date:** [December 19, 2020, 11:22pm UTC](https://discourse.julialang.org/t/groupby-reshaping-dataframe-with-unique-values/51149/18 "2020-12-19T23:22:29Z")

</div>

try this

```julia
dft=combine(groupby(df,"NAME"), [:CAT=>(t->sort!(t,by= x->(last(x) in "PF" ? lowercase(last(x)) : last(x))))=>:CAT,:CAT=>(t->string.("CAT",1:length(t)))=>:mm]) 
unstack(dft,:mm,:CAT)

```

---

_[View the full topic](https://discourse.julialang.org/t/groupby-reshaping-dataframe-with-unique-values/51149)._
