Label-based selection from a DataFrame
As we discussed back in the Position-based selection of a DataFrame section, the most common use case with a pd.DataFrame
is to use label-based selection when referring to columns and position-based selection when referring to rows. However, this is not an absolute requirement, and pandas allows you to use label-based selection from both the rows and columns.
When compared to other data analysis tools, the ability to select by label from the rows of a pd.DataFrame
is a unique advantage to pandas. For users familiar with SQL, there is no real equivalent to this provided by the language; columns are very easy to select when placed in a SELECT
clause, but rows can only be filtered via a WHERE
clause. For users adept at Microsoft Excel, you could create two-dimensional structures using a pivot table, with both row labels and column labels, but your ability to select or refer to data within that pivot table is effectively limited.
For now...