Creating new columns from unique values across rows in pandas
<p>I'm trying to use unique values in a pandas column to generate a new set of column. Here's an example <code>DataFrame</code>:</p>

<pre><code>    meas1  meas2  side  newindex
0       1      3     L         0
1       2      4     R         0
2       6      8     L         1
3       7      9     R         1
</code></pre>

<p>I'd like to "multiply" my measurement columns with my key columns to generate a <code>DafaFrame</code> that looks like this:</p>

<pre><code>   meas1_L  meas1_R  meas2_L  meas2_R
0        1        2        3        4
1        6        7        8        9
</code></pre>

<p>Note it's essentially the inverse of <a href="http://stackoverflow.com/q/39390615/512652">this question</a>.</p>

<p>Another solution using <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.core.groupby.GroupBy.prod.html" rel="nofollow"><code>groupby.prod</code></a>:</p>

<pre><code>df = df.groupby(['side', 'newindex']).prod().unstack(level=0)
df.columns = ['_'.join(c[0::]) for c in df.columns]

          meas1_L  meas1_R  meas2_L  meas2_R
newindex                                    
0               1        2        3        4
1               6        7        8        9
</code></pre>

python pandas dataframe