create matrix structure using pandas
<p>I have loaded the below CSV file containing code and coefficient data into the below dataframe df: </p>

<pre><code>CODE|COEFFICIENT  
A|0.5  
B|0.4  
C|0.3

import pandas as pd
import numpy as np
df= pd.read_csv('cod_coeff.csv', delimiter='|', encoding="utf-8-sig")
</code></pre>

<p>giving</p>

<pre><code>  ITEM   COEFFICIENT  
0    A       0.5  
1    B       0.4  
2    C       0.3  
</code></pre>

<p>From the above dataframe, I need to create a final dataframe as below which has a matrix structure with the product of the coefficients:</p>

<pre><code>     A         B         C        
A   0.25      0.2        0.15  
B   0.2       0.16       0.12  
C   0.15      0.12       0.09
</code></pre>

<p>I am using <code>np.multiply</code> but I am not successful in producing the result.</p>

<p>numpy as a faster alternative</p>

<pre><code>pd.DataFrame(np.outer(df, df), df.index, df.index)
</code></pre>

<p><a href="http://i.stack.imgur.com/hHaPR.png" rel="nofollow"><img src="http://i.stack.imgur.com/hHaPR.png" alt="enter image description here"></a></p>

<hr>

<h3>Timing</h3>

<p><strong><em>Given sample</em></strong></p>

<p><a href="http://i.stack.imgur.com/d8W0P.png" rel="nofollow"><img src="http://i.stack.imgur.com/d8W0P.png" alt="enter image description here"></a></p>

<p><strong><em>30,000 rows</em></strong></p>

<pre><code>df = pd.concat([df for _ in range(10000)], ignore_index=True)
</code></pre>

<p><a href="http://i.stack.imgur.com/Q5nee.png" rel="nofollow"><img src="http://i.stack.imgur.com/Q5nee.png" alt="enter image description here"></a></p>

python pandas numpy dataframe