Q:

Pandas: joining items with same index

I have a pandas data frame that is a vector with a value and an index, say:
row1  10
row1  11
row2  9
row2  8

However, I want to create a 2x2 matrix from this, in which the row index is actually a header (column index). Like this:
row1  row2
10    9
11    8

What is the most efficient way of doing this? This example is a simplification, but I could be dealing with thousands of data points. Does pandas have a specific function for joining items with same index into a table?
Observation: all indexes would have the same number of entries.

A:

assign another column to the index and unstack
s.index = [s.groupby(level=0).cumcount(), s.index]
s.unstack()

0  row1  row2
0    10     9
1    11     8

alternative numpy approach
still slower (blah...)
u, inv = np.unique(s.index.values, return_inverse=True)
data = dict(zip(u, [s.values[g] for g in (np.arange(len(u))[:, None] == inv)]))
pd.DataFrame(data)

