Multiplying pandas dataframe and series, element wise
<p>Lets say I have a pandas series:</p>

<pre><code>import pandas as pd
x = pd.DataFrame({0: [1,2,3], 1: [4,5,6], 2: [7,8,9] })
y = pd.Series([-1, 1, -1])
</code></pre>

<p>I want to multiply x and y in such a way that I get z:</p>

<pre><code>z = pd.DataFrame({0: [-1,2,-3], 1: [-4,5,-6], 2: [-7,8,-9] })
</code></pre>

<p>In other words, if element j of the series is -1, then all elements of the j-th row of x get multiplied by -1. If element k of the series is 1, then all elements of the j-th row of x get multiplied by 1. </p>

<p>How do I do this?</p>

<p>You can multiply the dataframes directly.</p>

<pre><code>x * y
</code></pre>

python pandas