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 ...
Get Learning pandas now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.