In [1]:
import numpy as np
import pandas as pd
from pandas import DataFrame, Series

In [2]:
import pandas.util.testing as tm
tm.N = 3

In [5]:
def unpivot(frame):
    N, K = frame.shape
    data = {'value': frame.values.ravel('F'), 
            'variable': np.asarray(frame.columns).repeat(N),
            'date': np.tile(np.asarray(frame.index), K)}
    
    return DataFrame(data, columns=['date', 'variable', 'value'])

In [6]:
dframe = unpivot(tm.makeTimeDataFrame())

In [7]:
dframe


Out[7]:
date variable value
0 2000-01-03 A 0.655934
1 2000-01-04 A 0.114627
2 2000-01-05 A 1.217039
3 2000-01-03 B 1.084729
4 2000-01-04 B -2.776063
5 2000-01-05 B 0.097573
6 2000-01-03 C 0.811582
7 2000-01-04 C 0.078955
8 2000-01-05 C -0.383991
9 2000-01-03 D 1.481837
10 2000-01-04 D -1.139894
11 2000-01-05 D 0.104460

In [8]:
dframe_piv = dframe.pivot('date', 'variable', 'value')
dframe_piv


Out[8]:
variable A B C D
date
2000-01-03 0.655934 1.084729 0.811582 1.481837
2000-01-04 0.114627 -2.776063 0.078955 -1.139894
2000-01-05 1.217039 0.097573 -0.383991 0.104460

In [ ]: