pandas multiply using dictionary values across several columns : <p>Given the following dataframe:</p>

<pre><code>import pandas as pd
df = pd.DataFrame({
    'a': [1,2,3,4,5],
    'b': [5,4,3,3,4],
    'c': [3,2,4,3,10],
    'd': [3, 2, 1, 1, 1]
})
</code></pre>

<p>And the following list of parameters:</p>

<pre><code>params = {'a': 2.5, 'b': 3.0, 'c': 1.3, 'd': 0.9}
</code></pre>

<p>Produce the following desired output:</p>

<pre><code>   a  b   c  d  output
0  1  5   3  3    24.1
1  2  4   2  2    21.4
2  3  3   4  1    22.6
3  4  3   3  1    23.8
4  5  4  10  1    38.4
</code></pre>

<p>I have been using this to produce the result:</p>

<pre><code>df['output'] = [np.sum(params[col] * df.loc[idx, col] for col in df)
                 for idx in df.index]
</code></pre>

<p>However, this is a very slow approach and I'm thinking there has to be a better way using built-in pandas functionality.</p>

<p>I also thought of this:</p>

<pre><code># Line up the parameters
col_sort_key = list(df)
params_sorted = sorted(params.items(), key=lambda k: col_sort_key.index(k[0]))

# Repeat the parameters *n* number of times
values = [v for k, v in params_sorted]
values = np.array([values] * df.shape[0])

values
array([[ 2.5,  3. ,  1.3,  0.9],
       [ 2.5,  3. ,  1.3,  0.9],
       [ 2.5,  3. ,  1.3,  0.9],
       [ 2.5,  3. ,  1.3,  0.9],
       [ 2.5,  3. ,  1.3,  0.9]])

# Multiply and add
product = df[col_sort_key].values * values
product
array([[  2.5,  15. ,   3.9,   2.7],
       [  5. ,  12. ,   2.6,   1.8],
       [  7.5,   9. ,   5.2,   0.9],
       [ 10. ,   9. ,   3.9,   0.9],
       [ 12.5,  12. ,  13. ,   0.9]])

np.sum(product, axis=1)
array([ 24.1,  21.4,  22.6,  23.8,  38.4])
</code></pre>

<p>But that seems a bit convoluted! Any thoughts on a native pandas try?</p>
