Divide two dataframes with python
<p>I have two dataframes : df1 and df2</p>

<p>df1 : </p>

<pre><code>TIMESTAMP eq1 eq2 eq3
2016-05-10 13:20:00 40 30 10
2016-05-10 13:40:00 40 10 20
</code></pre>

<p>df2 : </p>

<pre><code>TIMESTAMP eq1 eq2 eq3
2016-05-10 13:20:00 10 20 30
2016-05-10 13:40:00 10 20 20
</code></pre>

<p>I would like to divide df1 by df2 : each column of df1 by all column of df2 to get this result df3 : </p>

<pre><code>TIMESTAMP eq1 eq2 eq3
2016-05-10 13:20:00 40/(10+10) 30/(20+20) 10/(30+20)
2016-05-10 13:40:00 40/(10+10) 10/(20+20) 20/(30+20)
</code></pre>

<p>Any idea please ?</p>

<p>This should work if <code>TIMESTAMP</code> is not the index:</p>

<pre><code>&gt;&gt;&gt; df1.set_index('TIMESTAMP').div(df2.set_index('TIMESTAMP').sum()) 
                     eq1   eq2  eq3
TIMESTAMP                          
2016-05-10 13:20:00    2  0.75  0.2
2016-05-10 13:40:00    2  0.25  0.4
</code></pre>

<p>If <code>TIMESTAMP</code> is the index, then simply this:</p>

<pre><code>df1.div(df2.sum()) 
</code></pre>

python pandas dataframe multiple-columns division