Selecting certain features from a dataset according to a list.
<p>I have a <strong>dataset "h_train"</strong> which has about 26 features and I have a <strong>list</strong> <strong>H</strong> which has some selected features from the dataset "h_train". I would only like to keep those features in the "h_train" which are present in list H. </p>

<pre><code>h_train #Dataset with 26 features [A - Z]
H = ["A", "B", "C", "D"]
</code></pre>

<p>So I would like h_train to be reduced to only those features in H. How do I do it ?</p>

<p>Assuming <code>h_train</code> is a <code>pd.DataFrame</code> you can just do</p>

<pre><code>h_train = h_train[H]
</code></pre>

python pandas scikit-learn