Selecting rows and values of a DataFrame using the index
Elements of an array or Series are selected using the [] operator. DataFrame overloads [] to select columns instead of rows, except for a specific case of slicing. Therefore, most operations of selection of one or more rows in a DataFrame, require alternate methods to using [].
Understanding this is important in pandas, as it is a common mistake is try and select rows using [] due to familiarity with other languages or data structures. When doing so, errors are often received, and can often be difficult to diagnose without realizing [] is working along a completely different axis than with a Series object.
Row selection using the index on a DataFrame then breaks down to the following general categories of operations:
Slicing using the
[]operatorLabel or location based lookup using
.loc,.iloc, and.ixScalar lookup by label or location using
.atand.iat
We will briefly examine each of these techniques and attributes. Remember, all of...