Das Gegenteil von Schmelzen in python pandas

Ich kann nicht herausfinden, wie zu tun "reverse-Schmelze" mit Pandas in python.
Dies ist meine Start-Daten

import pandas as pd

from StringIO import StringIO

origin = pd.read_table(StringIO('''label    type    value
x   a   1
x   b   2
x   c   3
y   a   4
y   b   5
y   c   6
z   a   7
z   b   8
z   c   9'''))

origin
Out[5]: 
  label type  value
0     x    a      1
1     x    b      2
2     x    c      3
3     y    a      4
4     y    b      5
5     y    c      6
6     z    a      7
7     z    b      8
8     z    c      9

Dies ist die Ausgabe, die ich gerne haben möchte:

    label   a   b   c
        x   1   2   3
        y   4   5   6
        z   7   8   9

Ich bin sicher, es gibt eine einfache Möglichkeit, dies zu tun, aber ich weiß nicht, wie.

  • Docstring von Schmelzen: "Unpivots" ein DataFrame... 🙂
  • StringIO bewegt hat, zu io in Python ist3. verwenden from io import StringIO Python ist3.
  • Ich habe mehrere ausführliche Beispiele und alternative Ansätze in diesem Q&A
Schreibe einen Kommentar