Python Pandas: Generate dummy variable from numeric variable according to a threshold
<p>The goal is to create a new column from df with a 1 if the value from column '% Renewable' is at or above the median, and a 0 if the value is below the median.</p>

<pre><code>df = pd.DataFrame({'% Renewable': [np.NaN, 12, np.NaN, 11, 17, 62, 18, 15, np.NaN, 2, np.NaN, np.NaN, 6, np.NaN, 70]},
index=['China', 'United States', 'Japan', 'United Kingdom', 'Russian Federation', 'Canada', 'Germany', 'India', 'France', 'South Korea', 'Italy', 'Spain', 'Iran', 'Australia', 'Brazil'])
</code></pre>

<p>I got the median:</p>

<pre><code>median = df['% Renewable'].median()
</code></pre>

<p>But now what? Should I use get_dummies function? Or cut perhaps?</p>