Why does pandas dataframe indexing change axis depending on index type?
<p>when you index into a pandas dataframe using a list of ints, it returns columns.</p>

<p>e.g. <code>df[[0, 1, 2]]</code>  returns the first three columns.</p>

<p>why does indexing with a boolean vector return a list of rows?</p>

<p>e.g. <code>df[[True, False, True]]</code> returns the first and third rows. (and errors out if there aren't 3 rows.)</p>

<p>why? Shouldn't it return the first and third columns?</p>

<p>Thanks!</p>

<p>There are very specific slicing accessors to target rows and columns in specific ways.</p>

<p><a class='doc-link' href="http://stackoverflow.com/documentation/pandas/1751/indexing-and-selecting-data/5962/mixed-position-and-label-based-selection#t=201610120828283711024">Mixed position and label based selection</a></p>

<p><a class='doc-link' href="http://stackoverflow.com/documentation/pandas/1751/indexing-and-selecting-data/5732/selecting-by-position#t=201610120828283711024">Selecting by position</a></p>

<p><a class='doc-link' href="http://stackoverflow.com/documentation/pandas/1751/indexing-and-selecting-data/5684/selection-by-label#t=201610120828283711024">Selection By Label</a></p>

<ul>
<li><code>loc[]</code>, <code>at[]</code>, and <code>get_value()</code> take row and column labels and return the appropriate slice</li>
<li><code>iloc[]</code> and <code>iat[]</code> take row and column positions and return the appropriate slice</li>
</ul>

<p>What you are seeing is the result of <code>pandas</code> trying to infer what you are trying to do.  As you have noticed this is inconsistent at times.  In fact, it is more pronounced than just what you've highlighted... but I wont go into that now.</p>

<p>See also</p>

<p><a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.ix.html" rel="nofollow">pandas docs</a></p>

<blockquote>
<pre><code>However, when an axis is integer based,
ONLY label based access and not positional access is supported.
Thus, in such cases, itâs usually better to be explicit and use .iloc or .loc.
</code></pre>
</blockquote>

python pandas