exception when get a subset of a pandas data frame
<p>I want to get the first, 2nd and 4th column of a data frame, which is column <code>c_a,c_b,c_d</code>, what is wrong with my code?</p>

<p>I post my code, data (123.csv) and error message,</p>

<pre><code>sample = pd.read_csv('123.csv', header=None, skiprows=1,
    dtype={0:str, 1:str, 2:str, 3:float})
sample.columns = pd.Index(data=['c_a', 'c_b', 'c_c', 'c_d'])
sample['c_d'] = sample['c_d'].astype('int64')
print sample.shape # output (3, 4)
X = sample.iloc[0, 1, 3]

    raise IndexingError('Too many indexers')
pandas.core.indexing.IndexingError: Too many indexers
</code></pre>

<p>Content of 123.csv,</p>

<pre><code>c_a,c_b,c_c,c_d
hello,python,pandas,0.0
hi,java,pandas,1.0
ho,c++,numpy,0.0
</code></pre>

<p>You need to use <code>df.iloc[:, [0, 1, 3]]</code> instead (or <code>df[[0, 1, 3]]</code>).</p>

<p>Comma separates the row indexer and the column indexer. </p>

python python-2.7 pandas numpy dataframe