Skip to content

Feature Request : Reshape Data within DataTable #2499

@samukweku

Description

@samukweku
  • 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!

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions