How to multiply each row in pandas dataframe by a different value
<p>I am trying to multiply each row of a pandas dataframe by a different value and wondering what the best way to do this is.</p>

<p>For example if I have the following dataframe:</p>

<pre><code>import numpy as np
import pandas as pd
df = pd.DataFrame(np.random.randn(2, 3))
df
     0          1           2
0   -1.283316   0.849488    1.936060
1   -2.078575   -0.871570   -0.970261
</code></pre>

<p>I want to multiply each element of each row by a different in a list or array</p>

<pre><code>vals = [1, 100]
</code></pre>

<p>In this example I want each item in the first row to be multiplied by 1 and each item in the second row to be multiplied by 100</p>

<p>the result should therefore be:</p>

<pre><code>     0          1           2
0   -1.283316   0.849488    1.936060
1   -207.8575   -87.1570    -97.0261
</code></pre>

<p>I have tried:</p>

<pre><code>df * vals
df.multiply(vals)
df.multiply(vals, axis=1)
</code></pre>

<p>None of which work, although I was not expecting them too, based on my understanding of what that code should do. I can't figure out a concise way to do this with pandas, any help is appreciated, thanks.</p>