How to extract rows from a Pandas dataframe using .loc[]?

The Pandas loc[] method is used to select rows from a Pandas dataframe based on their index labels. It takes a list of index labels as input and returns a new dataframe containing only the rows with those labels. This method is useful for extracting specific rows from a dataframe or for subsetting the data based on certain criteria. For example, you might use the loc[] method to select rows that meet certain conditions or to select rows based on their position in the dataframe.

Example