To select rows from a DataFrame based on column values with Python Pandas, we can use the loc
property.
For instance, we write
df.loc[df['column_name'] == some_value]
to use the df.loc
fictionary to get the column value with the df['column_name'] == some_value
scalar.
We can combine conditions with &
or |
.
For instance, we write
df.loc[(df['column_name'] >= A) & (df['column_name'] <= B)]
to return the column values satifying df['column_name'] >= A
and df['column_name'] <= B
.