Feature Request : Reshape Data within DataTable
- Dominant language
- C++
- Stars
- 1.9k
- Forks
- 164
- Avg merge
- 7h 31m
- Merged PRs (30d)
- 1
Description
- convert data from wide to long, and vice versa (similar to ``melt/dcast`` in `rdatatable` or ``melt/pivot.pd.wide_to_long`` in ``pandas``)
# Example :
df = dt.Frame({"A":['a','b','c'], "B":[1,3,5],"C":[2,4,6]})
Transform from wide to long :
# new shape:
`A variable value`
` 0 a B 1`
`1 b B 3`
`2 c B 5`
`3 a C 2`
`4 b C 4`
`5 c C 6`
Transform from long to wide :
`A B C`
`0 a 1 2`
`1 b 3 4`
`2 c 5 6`
It would also be beneficial if there was flexibility in the reshaping, something similar to ``patterns`` in ``rdatatable`` that allows for regular expressions.
I currently hardcode the reshaping process, by building a list of dataframes, then ``rbind`` or ``cbind`` as the case may be.
**Note** : ``rbind`` does not accept a generator expression, only lists.
`` dt.rbind([df[:,f[0].extend({"var":name, "val":f[name]})] for name in df.names[1:]])``
Thanks!
Contributor guide
Assessment
This issue has not been assessed yet.