pandas.DataFrame.loc Property
This property is primarily label-based and used to access a group of rows and columns by label(s) or a boolean array.
Syntax:
property DataFrame.loc
Let us begin with an example to understand how we can select a row based on its column value.
DataFrame.loc[df['col-name'] == value]
To work with Python Pandas, we need to import the pandas library. Below is the syntax,
import pandas as pd
Python code to select rows from a DataFrame based on column values using loc property
Example 1:
Output:
Example 2:
Output:
need an explanation for this answer? contact us directly to get an explanation for this answer