1

如何转换这样的数据框:

          a         b         c
0  1.067683 -1.110463  0.208670
1 -1.321405  0.368915 -1.055342
2 -0.807333  0.082980 -0.873361

进入

    det     value
0     a  1.067683
1     a -1.321405
2     a -0.807333
3     b -1.110463
4     b  0.368915
5     b  0.082980
6     b  0.082980
7     c  0.208670
8     c -1.055342
9     c -0.873361
4

1 回答 1

3

你可以这样做melt

In [11]: from pandas.core.reshape import melt

In [12]: melt(df)
Out[12]:
  variable     value
0        a  1.067683
1        a -1.321405
2        a -0.807333
3        b -1.110463
4        b  0.368915
5        b  0.082980
6        c  0.208670
7        c -1.055342
8        c -0.873361
于 2013-07-05T20:00:12.510 回答