modin icon indicating copy to clipboard operation
modin copied to clipboard

Add support for `pd.wide_to_long()` (and possibly `pd.melt`)

Open mattschaelling opened this issue 4 years ago • 1 comments

I see that modin has already implemented pd.DataFrame.melt(). However, as far as I can tell, it doesn't have an implementation of the Pandas utility version of pd.melt(). There's another Pandas function that is pretty convenient — pd.wide_to_long() — and effectively only a wrapper around pd.melt(), so I was hoping it could be implemented without too much difficulty!

Here's the use case (from the Pandas docs):

>>> np.random.seed(123)
>>> df = pd.DataFrame({"A1970" : {0 : "a", 1 : "b", 2 : "c"},
...                    "A1980" : {0 : "d", 1 : "e", 2 : "f"},
...                    "B1970" : {0 : 2.5, 1 : 1.2, 2 : .7},
...                    "B1980" : {0 : 3.2, 1 : 1.3, 2 : .1},
...                    "X"     : dict(zip(range(3), np.random.randn(3)))
...                   })
>>> df["id"] = df.index
>>> df
  A1970 A1980  B1970  B1980         X  id
0     a     d    2.5    3.2 -1.085631   0
1     b     e    1.2    1.3  0.997345   1
2     c     f    0.7    0.1  0.282978   2
>>> pd.wide_to_long(df, ["A", "B"], i="id", j="year")
... 
                X  A    B
id year
0  1970 -1.085631  a  2.5
1  1970  0.997345  b  1.2
2  1970  0.282978  c  0.7
0  1980 -1.085631  d  3.2
1  1980  0.997345  e  1.3
2  1980  0.282978  f  0.1

mattschaelling avatar May 18 '21 21:05 mattschaelling

Hi @mattschaelling , thanks for posting, that would be a great addition! If you have a desire to implement it yourself, feel free to create a PR. Otherwise, we will take care of it.

YarShev avatar May 19 '21 10:05 YarShev