Python list or pandas dataframe arbitrary indexing and slicing
<p>I have used both R and Python extensively in my work, and at times I get the syntax between them confused.</p>

<p>In R, if I wanted to create a model from only <strong><em>some</em></strong> features of my data set, I can do something like this:</p>

<pre><code>subset = df[1:1000, c(1,5,14:18,24)]
</code></pre>

<p>This would take the first 1000 rows (yes, R starts on index 1), and it would take the 1st, 5th, 14th <strong><em>through</em></strong> 18th, and 24th columns.</p>

<p>I have tried to do any combination of <code>slice</code>, <code>range</code>, and similar sorts of functions, and have not been able to duplicate this sort of flexibility.  In the end, I just enumerated all of the values.</p>

<p>How can this be done in Python?</p>

<blockquote>
  <p>Pick an arbitrary subset of elements from a list, some of which are selected individually (as in the commas shown above) and some selected sequentially (as in the colons shown above)?</p>
</blockquote>

<p>Try this, The first square brackets filter. The second set of square brackets slice. </p>

<pre><code>df[[0,4]+ range(13,18)+[23]][:1000]
</code></pre>

python pandas numpy slice