dataframe column slices excluding specific columns
<p>How will i slice pandas dataframe with large number of columns, where  I do not wish to select specific and non-sequentially positioned columns? One option is to drop the specific columns, but can i do something like:</p>

<pre><code>df = pd.DataFrame(np.random.randint(0,100,(2,10)),columns=list('abcdefghij'))
df.iloc[:,~[1,4,9]]
</code></pre>

<p>you can do it this way:</p>

<pre><code>In [66]: cols2exclude = [1,4,9]

In [67]: df.ix[:, df.columns.difference(df.columns[cols2exclude])]
Out[67]:
    a   c   d   f   g   h   i
0  12  37  39  46  22  71  37
1  72   3  17  30  11  26  73
</code></pre>

<p>or:</p>

<pre><code>In [68]: df.ix[:, ~df.columns.isin(df.columns[cols2exclude])]
Out[68]:
    a   c   d   f   g   h   i
0  68  49  90   9  48  36  26
1   6  72  98  49  44  10  36
</code></pre>

python pandas dataframe slice