-
Notifications
You must be signed in to change notification settings - Fork 167
Open
Description
- convert data from wide to long, and vice versa (similar to
melt/dcastinrdatatableormelt/pivot.pd.wide_to_longinpandas)
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!
markfairbanks, mdancho84 and lmullany
Metadata
Metadata
Assignees
Labels
No labels